<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>16.1. os — Miscellaneous operating system interfaces &mdash; Python 3.4.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.4.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.4.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.4.3 documentation" href="../index.html" />
    <link rel="up" title="16. Generic Operating System Services" href="allos.html" />
    <link rel="next" title="16.2. io — Core tools for working with streams" href="io.html" />
    <link rel="prev" title="16. Generic Operating System Services" href="allos.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
 

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="16.2. io — Core tools for working with streams"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="16. Generic Operating System Services"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" accesskey="U">16. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-os">
<span id="os-miscellaneous-operating-system-interfaces"></span><h1>16.1. <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> &#8212; Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Permalink to this headline">¶</a></h1>
<p>This module provides a portable way of using operating system dependent
functionality.  If you just want to read or write a file see <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, if
you want to manipulate paths, see the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module, and if you want to
read all the lines in all the files on the command line see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><tt class="xref py py-mod docutils literal"><span class="pre">fileinput</span></tt></a>
module.  For creating temporary files and directories see the <a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a>
module, and for high-level file and directory handling see the <a class="reference internal" href="shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><tt class="xref py py-mod docutils literal"><span class="pre">shutil</span></tt></a>
module.</p>
<p>Notes on the availability of these functions:</p>
<ul class="simple">
<li>The design of all built-in operating system dependent modules of Python is
such that as long as the same functionality is available, it uses the same
interface; for example, the function <tt class="docutils literal"><span class="pre">os.stat(path)</span></tt> returns stat
information about <em>path</em> in the same format (which happens to have originated
with the POSIX interface).</li>
<li>Extensions peculiar to a particular operating system are also available
through the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module, but using them is of course a threat to
portability.</li>
<li>All functions accepting path or file names accept both bytes and string
objects, and result in an object of the same type, if a path or file name is
returned.</li>
<li>An &#8220;Availability: Unix&#8221; note means that this function is commonly found on
Unix systems.  It does not make any claims about its existence on a specific
operating system.</li>
<li>If not separately noted, all functions that claim &#8220;Availability: Unix&#8221; are
supported on Mac OS X, which builds on a Unix core.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All functions in this module raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> in the case of invalid or
inaccessible file names and paths, or other arguments that have the correct
type, but are not accepted by the operating system.</p>
</div>
<dl class="exception">
<dt id="os.error">
<em class="property">exception </em><tt class="descclassname">os.</tt><tt class="descname">error</tt><a class="headerlink" href="#os.error" title="Permalink to this definition">¶</a></dt>
<dd><p>An alias for the built-in <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exception.</p>
</dd></dl>

<dl class="data">
<dt id="os.name">
<tt class="descclassname">os.</tt><tt class="descname">name</tt><a class="headerlink" href="#os.name" title="Permalink to this definition">¶</a></dt>
<dd><p>The name of the operating system dependent module imported.  The following
names have currently been registered: <tt class="docutils literal"><span class="pre">'posix'</span></tt>, <tt class="docutils literal"><span class="pre">'nt'</span></tt>,
<tt class="docutils literal"><span class="pre">'ce'</span></tt>, <tt class="docutils literal"><span class="pre">'java'</span></tt>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><tt class="xref py py-attr docutils literal"><span class="pre">sys.platform</span></tt></a> has a finer granularity.  <a class="reference internal" href="#os.uname" title="os.uname"><tt class="xref py py-func docutils literal"><span class="pre">os.uname()</span></tt></a> gives
system-dependent version information.</p>
<p class="last">The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><tt class="xref py py-mod docutils literal"><span class="pre">platform</span></tt></a> module provides detailed checks for the
system&#8217;s identity.</p>
</div>
</dd></dl>

<div class="section" id="file-names-command-line-arguments-and-environment-variables">
<span id="filesystem-encoding"></span><span id="os-filenames"></span><h2>16.1.1. File Names, Command Line Arguments, and Environment Variables<a class="headerlink" href="#file-names-command-line-arguments-and-environment-variables" title="Permalink to this headline">¶</a></h2>
<p>In Python, file names, command line arguments, and environment variables are
represented using the string type. On some systems, decoding these strings to
and from bytes is necessary before passing them to the operating system. Python
uses the file system encoding to perform this conversion (see
<a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a>).</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.1: </span>On some systems, conversion using the file system encoding may fail. In this
case, Python uses the <tt class="docutils literal"><span class="pre">surrogateescape</span></tt> encoding error handler, which means
that undecodable bytes are replaced by a Unicode character U+DCxx on
decoding, and these are again translated to the original byte on encoding.</p>
</div>
<p>The file system encoding must guarantee to successfully decode all bytes
below 128. If the file system encoding fails to provide this guarantee, API
functions may raise UnicodeErrors.</p>
</div>
<div class="section" id="process-parameters">
<span id="os-procinfo"></span><h2>16.1.2. Process Parameters<a class="headerlink" href="#process-parameters" title="Permalink to this headline">¶</a></h2>
<p>These functions and data items provide information and operate on the current
process and user.</p>
<dl class="function">
<dt id="os.ctermid">
<tt class="descclassname">os.</tt><tt class="descname">ctermid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.ctermid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the filename corresponding to the controlling terminal of the process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.environ">
<tt class="descclassname">os.</tt><tt class="descname">environ</tt><a class="headerlink" href="#os.environ" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="../glossary.html#term-mapping"><em class="xref std std-term">mapping</em></a> object representing the string environment. For example,
<tt class="docutils literal"><span class="pre">environ['HOME']</span></tt> is the pathname of your home directory (on some platforms),
and is equivalent to <tt class="docutils literal"><span class="pre">getenv(&quot;HOME&quot;)</span></tt> in C.</p>
<p>This mapping is captured the first time the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module is imported,
typically during Python startup as part of processing <tt class="file docutils literal"><span class="pre">site.py</span></tt>.  Changes
to the environment made after this time are not reflected in <tt class="docutils literal"><span class="pre">os.environ</span></tt>,
except for changes made by modifying <tt class="docutils literal"><span class="pre">os.environ</span></tt> directly.</p>
<p>If the platform supports the <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> function, this mapping may be used
to modify the environment as well as query the environment.  <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> will
be called automatically when the mapping is modified.</p>
<p>On Unix, keys and values use <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a> and
<tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt> error handler. Use <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> if you would like
to use a different encoding.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Calling <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> directly does not change <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it&#8217;s better
to modify <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks.  Refer to the system documentation for
<tt class="xref c c-func docutils literal"><span class="pre">putenv()</span></tt>.</p>
</div>
<p>If <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is not provided, a modified copy of this mapping  may be
passed to the appropriate process-creation functions to cause  child processes
to use a modified environment.</p>
<p>If the platform supports the <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> function, you can delete items in
this mapping to unset environment variables. <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> will be called
automatically when an item is deleted from <tt class="docutils literal"><span class="pre">os.environ</span></tt>, and when
one of the <tt class="xref py py-meth docutils literal"><span class="pre">pop()</span></tt> or <tt class="xref py py-meth docutils literal"><span class="pre">clear()</span></tt> methods is called.</p>
</dd></dl>

<dl class="data">
<dt id="os.environb">
<tt class="descclassname">os.</tt><tt class="descname">environb</tt><a class="headerlink" href="#os.environb" title="Permalink to this definition">¶</a></dt>
<dd><p>Bytes version of <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a>: a <a class="reference internal" href="../glossary.html#term-mapping"><em class="xref std std-term">mapping</em></a> object representing the
environment as byte strings. <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a> and <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> are
synchronized (modify <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> updates <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a>, and vice
versa).</p>
<p><a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> is only available if <a class="reference internal" href="#os.supports_bytes_environ" title="os.supports_bytes_environ"><tt class="xref py py-data docutils literal"><span class="pre">supports_bytes_environ</span></tt></a> is
True.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt>
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big></dt>
<dd><p>These functions are described in <a class="reference internal" href="#os-file-dir"><em>Files and Directories</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.fsencode">
<tt class="descclassname">os.</tt><tt class="descname">fsencode</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#os.fsencode" title="Permalink to this definition">¶</a></dt>
<dd><p>Encode <em>filename</em> to the filesystem encoding with <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt>
error handler, or <tt class="docutils literal"><span class="pre">'strict'</span></tt> on Windows; return <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> unchanged.</p>
<p><a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><tt class="xref py py-func docutils literal"><span class="pre">fsdecode()</span></tt></a> is the reverse function.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.fsdecode">
<tt class="descclassname">os.</tt><tt class="descname">fsdecode</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#os.fsdecode" title="Permalink to this definition">¶</a></dt>
<dd><p>Decode <em>filename</em> from the filesystem encoding with <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt>
error handler, or <tt class="docutils literal"><span class="pre">'strict'</span></tt> on Windows; return <a class="reference internal" href="stdtypes.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a> unchanged.</p>
<p><a class="reference internal" href="#os.fsencode" title="os.fsencode"><tt class="xref py py-func docutils literal"><span class="pre">fsencode()</span></tt></a> is the reverse function.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getenv">
<tt class="descclassname">os.</tt><tt class="descname">getenv</tt><big>(</big><em>key</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#os.getenv" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value of the environment variable <em>key</em> if it exists, or
<em>default</em> if it doesn&#8217;t. <em>key</em>, <em>default</em> and the result are str.</p>
<p>On Unix, keys and values are decoded with <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a>
and <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt> error handler. Use <a class="reference internal" href="#os.getenvb" title="os.getenvb"><tt class="xref py py-func docutils literal"><span class="pre">os.getenvb()</span></tt></a> if you
would like to use a different encoding.</p>
<p>Availability: most flavors of Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getenvb">
<tt class="descclassname">os.</tt><tt class="descname">getenvb</tt><big>(</big><em>key</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#os.getenvb" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value of the environment variable <em>key</em> if it exists, or
<em>default</em> if it doesn&#8217;t. <em>key</em>, <em>default</em> and the result are bytes.</p>
<p>Availability: most flavors of Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.get_exec_path">
<tt class="descclassname">os.</tt><tt class="descname">get_exec_path</tt><big>(</big><em>env=None</em><big>)</big><a class="headerlink" href="#os.get_exec_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of directories that will be searched for a named
executable, similar to a shell, when launching a process.
<em>env</em>, when specified, should be an environment variable dictionary
to lookup the PATH in.
By default, when <em>env</em> is None, <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a> is used.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getegid">
<tt class="descclassname">os.</tt><tt class="descname">getegid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getegid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the effective group id of the current process.  This corresponds to the
&#8220;set id&#8221; bit on the file being executed in the current process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.geteuid">
<tt class="descclassname">os.</tt><tt class="descname">geteuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.geteuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-0">Return the current process&#8217;s effective user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgid">
<tt class="descclassname">os.</tt><tt class="descname">getgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-1">Return the real group id of the current process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgrouplist">
<tt class="descclassname">os.</tt><tt class="descname">getgrouplist</tt><big>(</big><em>user</em>, <em>group</em><big>)</big><a class="headerlink" href="#os.getgrouplist" title="Permalink to this definition">¶</a></dt>
<dd><p>Return list of group ids that <em>user</em> belongs to. If <em>group</em> is not in the
list, it is included; typically, <em>group</em> is specified as the group ID
field from the password record for <em>user</em>.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getgroups">
<tt class="descclassname">os.</tt><tt class="descname">getgroups</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Return list of supplemental group ids associated with the current process.</p>
<p>Availability: Unix.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On Mac OS X, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> behavior differs somewhat from
other Unix platforms. If the Python interpreter was built with a
deployment target of <tt class="xref py py-const docutils literal"><span class="pre">10.5</span></tt> or earlier, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> returns
the list of effective group ids associated with the current user process;
this list is limited to a system-defined number of entries, typically 16,
and may be modified by calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><tt class="xref py py-func docutils literal"><span class="pre">setgroups()</span></tt></a> if suitably privileged.
If built with a deployment target greater than <tt class="xref py py-const docutils literal"><span class="pre">10.5</span></tt>,
<a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> returns the current group access list for the user
associated with the effective user id of the process; the group access
list may change over the lifetime of the process, it is not affected by
calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><tt class="xref py py-func docutils literal"><span class="pre">setgroups()</span></tt></a>, and its length is not limited to 16.  The
deployment target value, <tt class="xref py py-const docutils literal"><span class="pre">MACOSX_DEPLOYMENT_TARGET</span></tt>, can be
obtained with <a class="reference internal" href="sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><tt class="xref py py-func docutils literal"><span class="pre">sysconfig.get_config_var()</span></tt></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getlogin">
<tt class="descclassname">os.</tt><tt class="descname">getlogin</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getlogin" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the name of the user logged in on the controlling terminal of the
process.  For most purposes, it is more useful to use the environment
variables <span class="target" id="index-2"></span><tt class="xref std std-envvar docutils literal"><span class="pre">LOGNAME</span></tt> or <span class="target" id="index-3"></span><tt class="xref std std-envvar docutils literal"><span class="pre">USERNAME</span></tt> to find out who the user
is, or <tt class="docutils literal"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></tt> to get the login name of the current
real user id.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpgid">
<tt class="descclassname">os.</tt><tt class="descname">getpgid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getpgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0,
the process group id of the current process is returned.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpgrp">
<tt class="descclassname">os.</tt><tt class="descname">getpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-4">Return the id of the current process group.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpid">
<tt class="descclassname">os.</tt><tt class="descname">getpid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-5">Return the current process id.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getppid">
<tt class="descclassname">os.</tt><tt class="descname">getppid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getppid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-6">Return the parent&#8217;s process id.  When the parent process has exited, on Unix
the id returned is the one of the init process (1), on Windows it is still
the same id, which may be already reused by another process.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>Added support for Windows.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getpriority">
<tt class="descclassname">os.</tt><tt class="descname">getpriority</tt><big>(</big><em>which</em>, <em>who</em><big>)</big><a class="headerlink" href="#os.getpriority" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-7">Get program scheduling priority.  The value <em>which</em> is one of
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PROCESS</span></tt></a>, <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PGRP</span></tt></a>, or <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_USER</span></tt></a>, and <em>who</em>
is interpreted relative to <em>which</em> (a process identifier for
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PROCESS</span></tt></a>, process group identifier for <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PGRP</span></tt></a>, and a
user ID for <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_USER</span></tt></a>).  A zero value for <em>who</em> denotes
(respectively) the calling process, the process group of the calling process,
or the real user ID of the calling process.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.PRIO_PROCESS">
<tt class="descclassname">os.</tt><tt class="descname">PRIO_PROCESS</tt><a class="headerlink" href="#os.PRIO_PROCESS" title="Permalink to this definition">¶</a></dt>
<dt id="os.PRIO_PGRP">
<tt class="descclassname">os.</tt><tt class="descname">PRIO_PGRP</tt><a class="headerlink" href="#os.PRIO_PGRP" title="Permalink to this definition">¶</a></dt>
<dt id="os.PRIO_USER">
<tt class="descclassname">os.</tt><tt class="descname">PRIO_USER</tt><a class="headerlink" href="#os.PRIO_USER" title="Permalink to this definition">¶</a></dt>
<dd><p>Parameters for the <a class="reference internal" href="#os.getpriority" title="os.getpriority"><tt class="xref py py-func docutils literal"><span class="pre">getpriority()</span></tt></a> and <a class="reference internal" href="#os.setpriority" title="os.setpriority"><tt class="xref py py-func docutils literal"><span class="pre">setpriority()</span></tt></a> functions.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getresuid">
<tt class="descclassname">os.</tt><tt class="descname">getresuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple (ruid, euid, suid) denoting the current process&#8217;s
real, effective, and saved user ids.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getresgid">
<tt class="descclassname">os.</tt><tt class="descname">getresgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple (rgid, egid, sgid) denoting the current process&#8217;s
real, effective, and saved group ids.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getuid">
<tt class="descclassname">os.</tt><tt class="descname">getuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-8">Return the current process&#8217;s real user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.initgroups">
<tt class="descclassname">os.</tt><tt class="descname">initgroups</tt><big>(</big><em>username</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.initgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system initgroups() to initialize the group access list with all of
the groups of which the specified username is a member, plus the specified
group id.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.putenv">
<tt class="descclassname">os.</tt><tt class="descname">putenv</tt><big>(</big><em>key</em>, <em>value</em><big>)</big><a class="headerlink" href="#os.putenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-9">Set the environment variable named <em>key</em> to the string <em>value</em>.  Such
changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>,
<a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p>
<p>Availability: most flavors of Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks. Refer to the system documentation for putenv.</p>
</div>
<p>When <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is supported, assignments to items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> are
automatically translated into corresponding calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a>; however,
calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to assign to items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="os.setegid">
<tt class="descclassname">os.</tt><tt class="descname">setegid</tt><big>(</big><em>egid</em><big>)</big><a class="headerlink" href="#os.setegid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s effective group id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.seteuid">
<tt class="descclassname">os.</tt><tt class="descname">seteuid</tt><big>(</big><em>euid</em><big>)</big><a class="headerlink" href="#os.seteuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s effective user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setgid">
<tt class="descclassname">os.</tt><tt class="descname">setgid</tt><big>(</big><em>gid</em><big>)</big><a class="headerlink" href="#os.setgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217; group id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setgroups">
<tt class="descclassname">os.</tt><tt class="descname">setgroups</tt><big>(</big><em>groups</em><big>)</big><a class="headerlink" href="#os.setgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the list of supplemental group ids associated with the current process to
<em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer
identifying a group. This operation is typically available only to the superuser.</p>
<p>Availability: Unix.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On Mac OS X, the length of <em>groups</em> may not exceed the
system-defined maximum number of effective group ids, typically 16.
See the documentation for <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> for cases where it may not
return the same group list set by calling setgroups().</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.setpgrp">
<tt class="descclassname">os.</tt><tt class="descname">setpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgrp()</span></tt> or <tt class="docutils literal"><span class="pre">setpgrp(0,</span> <span class="pre">0)</span></tt> depending on
which version is implemented (if any).  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setpgid">
<tt class="descclassname">os.</tt><tt class="descname">setpgid</tt><big>(</big><em>pid</em>, <em>pgrp</em><big>)</big><a class="headerlink" href="#os.setpgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgid()</span></tt> to set the process group id of the
process with id <em>pid</em> to the process group with id <em>pgrp</em>.  See the Unix manual
for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setpriority">
<tt class="descclassname">os.</tt><tt class="descname">setpriority</tt><big>(</big><em>which</em>, <em>who</em>, <em>priority</em><big>)</big><a class="headerlink" href="#os.setpriority" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-10">Set program scheduling priority. The value <em>which</em> is one of
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PROCESS</span></tt></a>, <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PGRP</span></tt></a>, or <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_USER</span></tt></a>, and <em>who</em>
is interpreted relative to <em>which</em> (a process identifier for
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PROCESS</span></tt></a>, process group identifier for <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_PGRP</span></tt></a>, and a
user ID for <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><tt class="xref py py-const docutils literal"><span class="pre">PRIO_USER</span></tt></a>). A zero value for <em>who</em> denotes
(respectively) the calling process, the process group of the calling process,
or the real user ID of the calling process.
<em>priority</em> is a value in the range -20 to 19. The default priority is 0;
lower priorities cause more favorable scheduling.</p>
<p>Availability: Unix</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.setregid">
<tt class="descclassname">os.</tt><tt class="descname">setregid</tt><big>(</big><em>rgid</em>, <em>egid</em><big>)</big><a class="headerlink" href="#os.setregid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real and effective group ids.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setresgid">
<tt class="descclassname">os.</tt><tt class="descname">setresgid</tt><big>(</big><em>rgid</em>, <em>egid</em>, <em>sgid</em><big>)</big><a class="headerlink" href="#os.setresgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real, effective, and saved group ids.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.setresuid">
<tt class="descclassname">os.</tt><tt class="descname">setresuid</tt><big>(</big><em>ruid</em>, <em>euid</em>, <em>suid</em><big>)</big><a class="headerlink" href="#os.setresuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real, effective, and saved user ids.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.setreuid">
<tt class="descclassname">os.</tt><tt class="descname">setreuid</tt><big>(</big><em>ruid</em>, <em>euid</em><big>)</big><a class="headerlink" href="#os.setreuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real and effective user ids.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getsid">
<tt class="descclassname">os.</tt><tt class="descname">getsid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getsid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">getsid()</span></tt>.  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setsid">
<tt class="descclassname">os.</tt><tt class="descname">setsid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setsid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setsid()</span></tt>.  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setuid">
<tt class="descclassname">os.</tt><tt class="descname">setuid</tt><big>(</big><em>uid</em><big>)</big><a class="headerlink" href="#os.setuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-11">Set the current process&#8217;s user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.strerror">
<tt class="descclassname">os.</tt><tt class="descname">strerror</tt><big>(</big><em>code</em><big>)</big><a class="headerlink" href="#os.strerror" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the error message corresponding to the error code in <em>code</em>.
On platforms where <tt class="xref c c-func docutils literal"><span class="pre">strerror()</span></tt> returns <tt class="docutils literal"><span class="pre">NULL</span></tt> when given an unknown
error number, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.supports_bytes_environ">
<tt class="descclassname">os.</tt><tt class="descname">supports_bytes_environ</tt><a class="headerlink" href="#os.supports_bytes_environ" title="Permalink to this definition">¶</a></dt>
<dd><p><tt class="docutils literal"><span class="pre">True</span></tt> if the native OS type of the environment is bytes (eg. <tt class="docutils literal"><span class="pre">False</span></tt> on
Windows).</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.umask">
<tt class="descclassname">os.</tt><tt class="descname">umask</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#os.umask" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current numeric umask and return the previous umask.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.uname">
<tt class="descclassname">os.</tt><tt class="descname">uname</tt><big>(</big><big>)</big><a class="headerlink" href="#os.uname" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-12">Returns information identifying the current operating system.
The return value is an object with five attributes:</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">sysname</span></tt> - operating system name</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">nodename</span></tt> - name of machine on network (implementation-defined)</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">release</span></tt> - operating system release</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">version</span></tt> - operating system version</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">machine</span></tt> - hardware identifier</li>
</ul>
<p>For backwards compatibility, this object is also iterable, behaving
like a five-tuple containing <tt class="xref py py-attr docutils literal"><span class="pre">sysname</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">nodename</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">release</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">version</span></tt>, and <tt class="xref py py-attr docutils literal"><span class="pre">machine</span></tt>
in that order.</p>
<p>Some systems truncate <tt class="xref py py-attr docutils literal"><span class="pre">nodename</span></tt> to 8 characters or to the
leading component; a better way to get the hostname is
<a class="reference internal" href="socket.html#socket.gethostname" title="socket.gethostname"><tt class="xref py py-func docutils literal"><span class="pre">socket.gethostname()</span></tt></a>  or even
<tt class="docutils literal"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></tt>.</p>
<p>Availability: recent flavors of Unix.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Return type changed from a tuple to a tuple-like object
with named attributes.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.unsetenv">
<tt class="descclassname">os.</tt><tt class="descname">unsetenv</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#os.unsetenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-13">Unset (delete) the environment variable named <em>key</em>. Such changes to the
environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>, <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or
<a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p>
<p>When <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> is supported, deletion of items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> is
automatically translated into a corresponding call to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a>; however,
calls to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to delete items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
<p>Availability: most flavors of Unix, Windows.</p>
</dd></dl>

</div>
<div class="section" id="file-object-creation">
<span id="os-newstreams"></span><h2>16.1.3. File Object Creation<a class="headerlink" href="#file-object-creation" title="Permalink to this headline">¶</a></h2>
<p>This function creates new <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file objects</em></a>.  (See also
<a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> for opening file descriptors.)</p>
<dl class="function">
<dt id="os.fdopen">
<tt class="descclassname">os.</tt><tt class="descname">fdopen</tt><big>(</big><em>fd</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#os.fdopen" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an open file object connected to the file descriptor <em>fd</em>.  This is an
alias of the <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> built-in function and accepts the same arguments.
The only difference is that the first argument of <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a> must always
be an integer.</p>
</dd></dl>

</div>
<div class="section" id="file-descriptor-operations">
<span id="os-fd-ops"></span><h2>16.1.4. File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Permalink to this headline">¶</a></h2>
<p>These functions operate on I/O streams referenced using file descriptors.</p>
<p>File descriptors are small integers corresponding to a file that has been opened
by the current process.  For example, standard input is usually file descriptor
0, standard output is 1, and standard error is 2.  Further files opened by a
process will then be assigned 3, 4, 5, and so forth.  The name &#8220;file descriptor&#8221;
is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
by file descriptors.</p>
<p>The <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><tt class="xref py py-meth docutils literal"><span class="pre">fileno()</span></tt></a> method can be used to obtain the file descriptor
associated with a <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> when required.  Note that using the file
descriptor directly will bypass the file object methods, ignoring aspects such
as internal buffering of data.</p>
<dl class="function">
<dt id="os.close">
<tt class="descclassname">os.</tt><tt class="descname">close</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close file descriptor <em>fd</em>.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To close a &#8220;file
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, use its <a class="reference internal" href="io.html#io.IOBase.close" title="io.IOBase.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> method.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.closerange">
<tt class="descclassname">os.</tt><tt class="descname">closerange</tt><big>(</big><em>fd_low</em>, <em>fd_high</em><big>)</big><a class="headerlink" href="#os.closerange" title="Permalink to this definition">¶</a></dt>
<dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive),
ignoring errors. Equivalent to (but much faster than):</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">fd_low</span><span class="p">,</span> <span class="n">fd_high</span><span class="p">):</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.device_encoding">
<tt class="descclassname">os.</tt><tt class="descname">device_encoding</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.device_encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string describing the encoding of the device associated with <em>fd</em>
if it is connected to a terminal; else return <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.dup">
<tt class="descclassname">os.</tt><tt class="descname">dup</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.dup" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a duplicate of file descriptor <em>fd</em>. The new file descriptor is
<a class="reference internal" href="#fd-inheritance"><em>non-inheritable</em></a>.</p>
<p>On Windows, when duplicating a standard stream (0: stdin, 1: stdout,
2: stderr), the new file descriptor is <a class="reference internal" href="#fd-inheritance"><em>inheritable</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.dup2">
<tt class="descclassname">os.</tt><tt class="descname">dup2</tt><big>(</big><em>fd</em>, <em>fd2</em>, <em>inheritable=True</em><big>)</big><a class="headerlink" href="#os.dup2" title="Permalink to this definition">¶</a></dt>
<dd><p>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if necessary.
The file descriptor <em>fd2</em> is <a class="reference internal" href="#fd-inheritance"><em>inheritable</em></a> by default,
or non-inheritable if <em>inheritable</em> is <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>Add the optional <em>inheritable</em> parameter.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.fchmod">
<tt class="descclassname">os.</tt><tt class="descname">fchmod</tt><big>(</big><em>fd</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.fchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>.  See the
docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a> for possible values of <em>mode</em>.  As of Python 3.3, this
is equivalent to <tt class="docutils literal"><span class="pre">os.chmod(fd,</span> <span class="pre">mode)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchown">
<tt class="descclassname">os.</tt><tt class="descname">fchown</tt><big>(</big><em>fd</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.fchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em>
and <em>gid</em>.  To leave one of the ids unchanged, set it to -1.  See
<a class="reference internal" href="#os.chown" title="os.chown"><tt class="xref py py-func docutils literal"><span class="pre">chown()</span></tt></a>.  As of Python 3.3, this is equivalent to <tt class="docutils literal"><span class="pre">os.chown(fd,</span> <span class="pre">uid,</span>
<span class="pre">gid)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fdatasync">
<tt class="descclassname">os.</tt><tt class="descname">fdatasync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fdatasync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of
metadata.</p>
<p>Availability: Unix.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is not available on MacOS.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.fpathconf">
<tt class="descclassname">os.</tt><tt class="descname">fpathconf</tt><big>(</big><em>fd</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.fpathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to an open file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>As of Python 3.3, this is equivalent to <tt class="docutils literal"><span class="pre">os.pathconf(fd,</span> <span class="pre">name)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fstat">
<tt class="descclassname">os.</tt><tt class="descname">fstat</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstat" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the status of the file descriptor <em>fd</em>. Return a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a>
object.</p>
<p>As of Python 3.3, this is equivalent to <tt class="docutils literal"><span class="pre">os.stat(fd)</span></tt>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> function.</p>
</div>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.fstatvfs">
<tt class="descclassname">os.</tt><tt class="descname">fstatvfs</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstatvfs" title="Permalink to this definition">¶</a></dt>
<dd><p>Return information about the filesystem containing the file associated with
file descriptor <em>fd</em>, like <a class="reference internal" href="#os.statvfs" title="os.statvfs"><tt class="xref py py-func docutils literal"><span class="pre">statvfs()</span></tt></a>.  As of Python 3.3, this is
equivalent to <tt class="docutils literal"><span class="pre">os.statvfs(fd)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fsync">
<tt class="descclassname">os.</tt><tt class="descname">fsync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fsync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk.  On Unix, this calls the
native <tt class="xref c c-func docutils literal"><span class="pre">fsync()</span></tt> function; on Windows, the MS <tt class="xref c c-func docutils literal"><span class="pre">_commit()</span></tt> function.</p>
<p>If you&#8217;re starting with a buffered Python <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> <em>f</em>, first do
<tt class="docutils literal"><span class="pre">f.flush()</span></tt>, and then do <tt class="docutils literal"><span class="pre">os.fsync(f.fileno())</span></tt>, to ensure that all internal
buffers associated with <em>f</em> are written to disk.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.ftruncate">
<tt class="descclassname">os.</tt><tt class="descname">ftruncate</tt><big>(</big><em>fd</em>, <em>length</em><big>)</big><a class="headerlink" href="#os.ftruncate" title="Permalink to this definition">¶</a></dt>
<dd><p>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at
most <em>length</em> bytes in size.  As of Python 3.3, this is equivalent to
<tt class="docutils literal"><span class="pre">os.truncate(fd,</span> <span class="pre">length)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.isatty">
<tt class="descclassname">os.</tt><tt class="descname">isatty</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.isatty" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the file descriptor <em>fd</em> is open and connected to a
tty(-like) device, else <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="os.lockf">
<tt class="descclassname">os.</tt><tt class="descname">lockf</tt><big>(</big><em>fd</em>, <em>cmd</em>, <em>len</em><big>)</big><a class="headerlink" href="#os.lockf" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply, test or remove a POSIX lock on an open file descriptor.
<em>fd</em> is an open file descriptor.
<em>cmd</em> specifies the command to use - one of <a class="reference internal" href="#os.F_LOCK" title="os.F_LOCK"><tt class="xref py py-data docutils literal"><span class="pre">F_LOCK</span></tt></a>, <a class="reference internal" href="#os.F_TLOCK" title="os.F_TLOCK"><tt class="xref py py-data docutils literal"><span class="pre">F_TLOCK</span></tt></a>,
<a class="reference internal" href="#os.F_ULOCK" title="os.F_ULOCK"><tt class="xref py py-data docutils literal"><span class="pre">F_ULOCK</span></tt></a> or <a class="reference internal" href="#os.F_TEST" title="os.F_TEST"><tt class="xref py py-data docutils literal"><span class="pre">F_TEST</span></tt></a>.
<em>len</em> specifies the section of the file to lock.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.F_LOCK">
<tt class="descclassname">os.</tt><tt class="descname">F_LOCK</tt><a class="headerlink" href="#os.F_LOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.F_TLOCK">
<tt class="descclassname">os.</tt><tt class="descname">F_TLOCK</tt><a class="headerlink" href="#os.F_TLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.F_ULOCK">
<tt class="descclassname">os.</tt><tt class="descname">F_ULOCK</tt><a class="headerlink" href="#os.F_ULOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.F_TEST">
<tt class="descclassname">os.</tt><tt class="descname">F_TEST</tt><a class="headerlink" href="#os.F_TEST" title="Permalink to this definition">¶</a></dt>
<dd><p>Flags that specify what action <a class="reference internal" href="#os.lockf" title="os.lockf"><tt class="xref py py-func docutils literal"><span class="pre">lockf()</span></tt></a> will take.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.lseek">
<tt class="descclassname">os.</tt><tt class="descname">lseek</tt><big>(</big><em>fd</em>, <em>pos</em>, <em>how</em><big>)</big><a class="headerlink" href="#os.lseek" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified
by <em>how</em>: <a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_SET</span></tt></a> or <tt class="docutils literal"><span class="pre">0</span></tt> to set the position relative to the
beginning of the file; <a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_CUR</span></tt></a> or <tt class="docutils literal"><span class="pre">1</span></tt> to set it relative to the
current position; <a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_END</span></tt></a> or <tt class="docutils literal"><span class="pre">2</span></tt> to set it relative to the end of
the file. Return the new cursor position in bytes, starting from the beginning.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.SEEK_SET">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_SET</tt><a class="headerlink" href="#os.SEEK_SET" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_CUR">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_CUR</tt><a class="headerlink" href="#os.SEEK_CUR" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_END">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_END</tt><a class="headerlink" href="#os.SEEK_END" title="Permalink to this definition">¶</a></dt>
<dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><tt class="xref py py-func docutils literal"><span class="pre">lseek()</span></tt></a> function. Their values are 0, 1, and 2,
respectively.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Some operating systems could support additional values, like
<tt class="xref py py-data docutils literal"><span class="pre">os.SEEK_HOLE</span></tt> or <tt class="xref py py-data docutils literal"><span class="pre">os.SEEK_DATA</span></tt>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.open">
<tt class="descclassname">os.</tt><tt class="descname">open</tt><big>(</big><em>file</em>, <em>flags</em>, <em>mode=0o777</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open the file <em>file</em> and set various flags according to <em>flags</em> and possibly
its mode according to <em>mode</em>.  When computing <em>mode</em>, the current umask value
is first masked out.  Return the file descriptor for the newly opened file.
The new file descriptor is <a class="reference internal" href="#fd-inheritance"><em>non-inheritable</em></a>.</p>
<p>For a description of the flag and mode values, see the C run-time documentation;
flag constants (like <a class="reference internal" href="#os.O_RDONLY" title="os.O_RDONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_RDONLY</span></tt></a> and <a class="reference internal" href="#os.O_WRONLY" title="os.O_WRONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_WRONLY</span></tt></a>) are defined in
the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module.  In particular, on Windows adding
<a class="reference internal" href="#os.O_BINARY" title="os.O_BINARY"><tt class="xref py py-const docutils literal"><span class="pre">O_BINARY</span></tt></a> is needed to open files in binary mode.</p>
<p>This function can support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a> with the <em>dir_fd</em> parameter.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O.  For normal usage, use the
built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, which returns a <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> with
<tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> methods (and many more).  To
wrap a file descriptor in a file object, use <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<p>The following constants are options for the <em>flags</em> parameter to the
<a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function.  They can be combined using the bitwise OR operator
<tt class="docutils literal"><span class="pre">|</span></tt>.  Some of them are not available on all platforms.  For descriptions of
their availability and use, consult the <em class="manpage">open(2)</em> manual page on Unix
or <a class="reference external" href="http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx">the MSDN</a> on Windows.</p>
<dl class="data">
<dt id="os.O_RDONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_RDONLY</tt><a class="headerlink" href="#os.O_RDONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_WRONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_WRONLY</tt><a class="headerlink" href="#os.O_WRONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RDWR">
<tt class="descclassname">os.</tt><tt class="descname">O_RDWR</tt><a class="headerlink" href="#os.O_RDWR" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_APPEND">
<tt class="descclassname">os.</tt><tt class="descname">O_APPEND</tt><a class="headerlink" href="#os.O_APPEND" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_CREAT">
<tt class="descclassname">os.</tt><tt class="descname">O_CREAT</tt><a class="headerlink" href="#os.O_CREAT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXCL">
<tt class="descclassname">os.</tt><tt class="descname">O_EXCL</tt><a class="headerlink" href="#os.O_EXCL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TRUNC">
<tt class="descclassname">os.</tt><tt class="descname">O_TRUNC</tt><a class="headerlink" href="#os.O_TRUNC" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are available on Unix and Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.O_DSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_DSYNC</tt><a class="headerlink" href="#os.O_DSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_RSYNC</tt><a class="headerlink" href="#os.O_RSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_SYNC</tt><a class="headerlink" href="#os.O_SYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NDELAY">
<tt class="descclassname">os.</tt><tt class="descname">O_NDELAY</tt><a class="headerlink" href="#os.O_NDELAY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NONBLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_NONBLOCK</tt><a class="headerlink" href="#os.O_NONBLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOCTTY">
<tt class="descclassname">os.</tt><tt class="descname">O_NOCTTY</tt><a class="headerlink" href="#os.O_NOCTTY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_SHLOCK</tt><a class="headerlink" href="#os.O_SHLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_EXLOCK</tt><a class="headerlink" href="#os.O_EXLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_CLOEXEC">
<tt class="descclassname">os.</tt><tt class="descname">O_CLOEXEC</tt><a class="headerlink" href="#os.O_CLOEXEC" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are only available on Unix.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Add <a class="reference internal" href="#os.O_CLOEXEC" title="os.O_CLOEXEC"><tt class="xref py py-data docutils literal"><span class="pre">O_CLOEXEC</span></tt></a> constant.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.O_BINARY">
<tt class="descclassname">os.</tt><tt class="descname">O_BINARY</tt><a class="headerlink" href="#os.O_BINARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOINHERIT">
<tt class="descclassname">os.</tt><tt class="descname">O_NOINHERIT</tt><a class="headerlink" href="#os.O_NOINHERIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHORT_LIVED">
<tt class="descclassname">os.</tt><tt class="descname">O_SHORT_LIVED</tt><a class="headerlink" href="#os.O_SHORT_LIVED" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEMPORARY">
<tt class="descclassname">os.</tt><tt class="descname">O_TEMPORARY</tt><a class="headerlink" href="#os.O_TEMPORARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RANDOM">
<tt class="descclassname">os.</tt><tt class="descname">O_RANDOM</tt><a class="headerlink" href="#os.O_RANDOM" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SEQUENTIAL">
<tt class="descclassname">os.</tt><tt class="descname">O_SEQUENTIAL</tt><a class="headerlink" href="#os.O_SEQUENTIAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEXT">
<tt class="descclassname">os.</tt><tt class="descname">O_TEXT</tt><a class="headerlink" href="#os.O_TEXT" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are only available on Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.O_ASYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_ASYNC</tt><a class="headerlink" href="#os.O_ASYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECT">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECT</tt><a class="headerlink" href="#os.O_DIRECT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECTORY">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECTORY</tt><a class="headerlink" href="#os.O_DIRECTORY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOFOLLOW">
<tt class="descclassname">os.</tt><tt class="descname">O_NOFOLLOW</tt><a class="headerlink" href="#os.O_NOFOLLOW" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOATIME">
<tt class="descclassname">os.</tt><tt class="descname">O_NOATIME</tt><a class="headerlink" href="#os.O_NOATIME" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_PATH">
<tt class="descclassname">os.</tt><tt class="descname">O_PATH</tt><a class="headerlink" href="#os.O_PATH" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TMPFILE">
<tt class="descclassname">os.</tt><tt class="descname">O_TMPFILE</tt><a class="headerlink" href="#os.O_TMPFILE" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are GNU extensions and not present if they are not defined by
the C library.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>Add <a class="reference internal" href="#os.O_PATH" title="os.O_PATH"><tt class="xref py py-data docutils literal"><span class="pre">O_PATH</span></tt></a> on systems that support it.
Add <a class="reference internal" href="#os.O_TMPFILE" title="os.O_TMPFILE"><tt class="xref py py-data docutils literal"><span class="pre">O_TMPFILE</span></tt></a>, only available on Linux Kernel 3.11
  or newer.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.openpty">
<tt class="descclassname">os.</tt><tt class="descname">openpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.openpty" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-14">Open a new pseudo-terminal pair. Return a pair of file descriptors
<tt class="docutils literal"><span class="pre">(master,</span> <span class="pre">slave)</span></tt> for the pty and the tty, respectively. The new file
descriptors are <a class="reference internal" href="#fd-inheritance"><em>non-inheritable</em></a>. For a (slightly) more
portable approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module.</p>
<p>Availability: some flavors of Unix.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>The new file descriptors are now non-inheritable.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.pipe">
<tt class="descclassname">os.</tt><tt class="descname">pipe</tt><big>(</big><big>)</big><a class="headerlink" href="#os.pipe" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a pipe.  Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></tt> usable for
reading and writing, respectively. The new file descriptor is
<a class="reference internal" href="#fd-inheritance"><em>non-inheritable</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>The new file descriptors are now non-inheritable.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.pipe2">
<tt class="descclassname">os.</tt><tt class="descname">pipe2</tt><big>(</big><em>flags</em><big>)</big><a class="headerlink" href="#os.pipe2" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a pipe with <em>flags</em> set atomically.
<em>flags</em> can be constructed by ORing together one or more of these values:
<a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><tt class="xref py py-data docutils literal"><span class="pre">O_NONBLOCK</span></tt></a>, <a class="reference internal" href="#os.O_CLOEXEC" title="os.O_CLOEXEC"><tt class="xref py py-data docutils literal"><span class="pre">O_CLOEXEC</span></tt></a>.
Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></tt> usable for reading and writing,
respectively.</p>
<p>Availability: some flavors of Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.posix_fallocate">
<tt class="descclassname">os.</tt><tt class="descname">posix_fallocate</tt><big>(</big><em>fd</em>, <em>offset</em>, <em>len</em><big>)</big><a class="headerlink" href="#os.posix_fallocate" title="Permalink to this definition">¶</a></dt>
<dd><p>Ensures that enough disk space is allocated for the file specified by <em>fd</em>
starting from <em>offset</em> and continuing for <em>len</em> bytes.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.posix_fadvise">
<tt class="descclassname">os.</tt><tt class="descname">posix_fadvise</tt><big>(</big><em>fd</em>, <em>offset</em>, <em>len</em>, <em>advice</em><big>)</big><a class="headerlink" href="#os.posix_fadvise" title="Permalink to this definition">¶</a></dt>
<dd><p>Announces an intention to access data in a specific pattern thus allowing
the kernel to make optimizations.
The advice applies to the region of the file specified by <em>fd</em> starting at
<em>offset</em> and continuing for <em>len</em> bytes.
<em>advice</em> is one of <a class="reference internal" href="#os.POSIX_FADV_NORMAL" title="os.POSIX_FADV_NORMAL"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_NORMAL</span></tt></a>, <a class="reference internal" href="#os.POSIX_FADV_SEQUENTIAL" title="os.POSIX_FADV_SEQUENTIAL"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_SEQUENTIAL</span></tt></a>,
<a class="reference internal" href="#os.POSIX_FADV_RANDOM" title="os.POSIX_FADV_RANDOM"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_RANDOM</span></tt></a>, <a class="reference internal" href="#os.POSIX_FADV_NOREUSE" title="os.POSIX_FADV_NOREUSE"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_NOREUSE</span></tt></a>,
<a class="reference internal" href="#os.POSIX_FADV_WILLNEED" title="os.POSIX_FADV_WILLNEED"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_WILLNEED</span></tt></a> or <a class="reference internal" href="#os.POSIX_FADV_DONTNEED" title="os.POSIX_FADV_DONTNEED"><tt class="xref py py-data docutils literal"><span class="pre">POSIX_FADV_DONTNEED</span></tt></a>.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.POSIX_FADV_NORMAL">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_NORMAL</tt><a class="headerlink" href="#os.POSIX_FADV_NORMAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.POSIX_FADV_SEQUENTIAL">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_SEQUENTIAL</tt><a class="headerlink" href="#os.POSIX_FADV_SEQUENTIAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.POSIX_FADV_RANDOM">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_RANDOM</tt><a class="headerlink" href="#os.POSIX_FADV_RANDOM" title="Permalink to this definition">¶</a></dt>
<dt id="os.POSIX_FADV_NOREUSE">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_NOREUSE</tt><a class="headerlink" href="#os.POSIX_FADV_NOREUSE" title="Permalink to this definition">¶</a></dt>
<dt id="os.POSIX_FADV_WILLNEED">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_WILLNEED</tt><a class="headerlink" href="#os.POSIX_FADV_WILLNEED" title="Permalink to this definition">¶</a></dt>
<dt id="os.POSIX_FADV_DONTNEED">
<tt class="descclassname">os.</tt><tt class="descname">POSIX_FADV_DONTNEED</tt><a class="headerlink" href="#os.POSIX_FADV_DONTNEED" title="Permalink to this definition">¶</a></dt>
<dd><p>Flags that can be used in <em>advice</em> in <a class="reference internal" href="#os.posix_fadvise" title="os.posix_fadvise"><tt class="xref py py-func docutils literal"><span class="pre">posix_fadvise()</span></tt></a> that specify
the access pattern that is likely to be used.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.pread">
<tt class="descclassname">os.</tt><tt class="descname">pread</tt><big>(</big><em>fd</em>, <em>buffersize</em>, <em>offset</em><big>)</big><a class="headerlink" href="#os.pread" title="Permalink to this definition">¶</a></dt>
<dd><p>Read from a file descriptor, <em>fd</em>, at a position of <em>offset</em>. It will read up
to <em>buffersize</em> number of bytes. The file offset remains unchanged.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.pwrite">
<tt class="descclassname">os.</tt><tt class="descname">pwrite</tt><big>(</big><em>fd</em>, <em>str</em>, <em>offset</em><big>)</big><a class="headerlink" href="#os.pwrite" title="Permalink to this definition">¶</a></dt>
<dd><p>Write <em>bytestring</em> to a file descriptor, <em>fd</em>, from <em>offset</em>,
leaving the file offset unchanged.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.read">
<tt class="descclassname">os.</tt><tt class="descname">read</tt><big>(</big><em>fd</em>, <em>n</em><big>)</big><a class="headerlink" href="#os.read" title="Permalink to this definition">¶</a></dt>
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>. Return a bytestring containing the
bytes read.  If the end of the file referred to by <em>fd</em> has been reached, an
empty bytes object is returned.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To read a
&#8220;file object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by
<a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, use its
<tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt> or <tt class="xref py py-meth docutils literal"><span class="pre">readline()</span></tt> methods.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.sendfile">
<tt class="descclassname">os.</tt><tt class="descname">sendfile</tt><big>(</big><em>out</em>, <em>in</em>, <em>offset</em>, <em>nbytes</em><big>)</big><a class="headerlink" href="#os.sendfile" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">sendfile</tt><big>(</big><em>out</em>, <em>in</em>, <em>offset</em>, <em>nbytes</em>, <em>headers=None</em>, <em>trailers=None</em>, <em>flags=0</em><big>)</big></dt>
<dd><p>Copy <em>nbytes</em> bytes from file descriptor <em>in</em> to file descriptor <em>out</em>
starting at <em>offset</em>.
Return the number of bytes sent. When EOF is reached return 0.</p>
<p>The first function notation is supported by all platforms that define
<a class="reference internal" href="#os.sendfile" title="os.sendfile"><tt class="xref py py-func docutils literal"><span class="pre">sendfile()</span></tt></a>.</p>
<p>On Linux, if <em>offset</em> is given as <tt class="docutils literal"><span class="pre">None</span></tt>, the bytes are read from the
current position of <em>in</em> and the position of <em>in</em> is updated.</p>
<p>The second case may be used on Mac OS X and FreeBSD where <em>headers</em> and
<em>trailers</em> are arbitrary sequences of buffers that are written before and
after the data from <em>in</em> is written. It returns the same as the first case.</p>
<p>On Mac OS X and FreeBSD, a value of 0 for <em>nbytes</em> specifies to send until
the end of <em>in</em> is reached.</p>
<p>All platforms support sockets as <em>out</em> file descriptor, and some platforms
allow other types (e.g. regular file, pipe) as well.</p>
<p>Cross-platform applications should not use <em>headers</em>, <em>trailers</em> and <em>flags</em>
arguments.</p>
<p>Availability: Unix.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For a higher-level wrapper of <a class="reference internal" href="#os.sendfile" title="os.sendfile"><tt class="xref py py-func docutils literal"><span class="pre">sendfile()</span></tt></a>, see
<tt class="xref py py-mod docutils literal"><span class="pre">socket.socket.sendfile</span></tt>.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.SF_NODISKIO">
<tt class="descclassname">os.</tt><tt class="descname">SF_NODISKIO</tt><a class="headerlink" href="#os.SF_NODISKIO" title="Permalink to this definition">¶</a></dt>
<dt id="os.SF_MNOWAIT">
<tt class="descclassname">os.</tt><tt class="descname">SF_MNOWAIT</tt><a class="headerlink" href="#os.SF_MNOWAIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.SF_SYNC">
<tt class="descclassname">os.</tt><tt class="descname">SF_SYNC</tt><a class="headerlink" href="#os.SF_SYNC" title="Permalink to this definition">¶</a></dt>
<dd><p>Parameters to the <a class="reference internal" href="#os.sendfile" title="os.sendfile"><tt class="xref py py-func docutils literal"><span class="pre">sendfile()</span></tt></a> function, if the implementation supports
them.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.readv">
<tt class="descclassname">os.</tt><tt class="descname">readv</tt><big>(</big><em>fd</em>, <em>buffers</em><big>)</big><a class="headerlink" href="#os.readv" title="Permalink to this definition">¶</a></dt>
<dd><p>Read from a file descriptor <em>fd</em> into a number of mutable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><em class="xref std std-term">bytes-like
objects</em></a> <em>buffers</em>. <a class="reference internal" href="#os.readv" title="os.readv"><tt class="xref py py-func docutils literal"><span class="pre">readv()</span></tt></a> will transfer data
into each buffer until it is full and then move on to the next buffer in the
sequence to hold the rest of the data. <a class="reference internal" href="#os.readv" title="os.readv"><tt class="xref py py-func docutils literal"><span class="pre">readv()</span></tt></a> returns the total
number of bytes read (which may be less than the total capacity of all the
objects).</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.tcgetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcgetpgrp</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.tcgetpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the process group associated with the terminal given by <em>fd</em> (an open
file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>).</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.tcsetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcsetpgrp</tt><big>(</big><em>fd</em>, <em>pg</em><big>)</big><a class="headerlink" href="#os.tcsetpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the process group associated with the terminal given by <em>fd</em> (an open file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>) to <em>pg</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.ttyname">
<tt class="descclassname">os.</tt><tt class="descname">ttyname</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.ttyname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string which specifies the terminal device associated with
file descriptor <em>fd</em>.  If <em>fd</em> is not associated with a terminal device, an
exception is raised.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.write">
<tt class="descclassname">os.</tt><tt class="descname">write</tt><big>(</big><em>fd</em>, <em>str</em><big>)</big><a class="headerlink" href="#os.write" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the bytestring in <em>str</em> to file descriptor <em>fd</em>. Return the number of
bytes actually written.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To write a &#8220;file
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></tt></a> or <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><tt class="xref py py-data docutils literal"><span class="pre">sys.stderr</span></tt></a>, use its
<tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> method.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.writev">
<tt class="descclassname">os.</tt><tt class="descname">writev</tt><big>(</big><em>fd</em>, <em>buffers</em><big>)</big><a class="headerlink" href="#os.writev" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the contents of <em>buffers</em> to file descriptor <em>fd</em>. <em>buffers</em> must be a
sequence of <a class="reference internal" href="../glossary.html#term-bytes-like-object"><em class="xref std std-term">bytes-like objects</em></a>.
<a class="reference internal" href="#os.writev" title="os.writev"><tt class="xref py py-func docutils literal"><span class="pre">writev()</span></tt></a> writes the contents of each object to the file descriptor
and returns the total number of bytes written.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<div class="section" id="querying-the-size-of-a-terminal">
<span id="terminal-size"></span><h3>16.1.4.1. Querying the size of a terminal<a class="headerlink" href="#querying-the-size-of-a-terminal" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
<dl class="function">
<dt id="os.get_terminal_size">
<tt class="descclassname">os.</tt><tt class="descname">get_terminal_size</tt><big>(</big><em>fd=STDOUT_FILENO</em><big>)</big><a class="headerlink" href="#os.get_terminal_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the size of the terminal window as <tt class="docutils literal"><span class="pre">(columns,</span> <span class="pre">lines)</span></tt>,
tuple of type <a class="reference internal" href="#os.terminal_size" title="os.terminal_size"><tt class="xref py py-class docutils literal"><span class="pre">terminal_size</span></tt></a>.</p>
<p>The optional argument <tt class="docutils literal"><span class="pre">fd</span></tt> (default <tt class="docutils literal"><span class="pre">STDOUT_FILENO</span></tt>, or standard
output) specifies which file descriptor should be queried.</p>
<p>If the file descriptor is not connected to a terminal, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a>
is raised.</p>
<p><a class="reference internal" href="shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><tt class="xref py py-func docutils literal"><span class="pre">shutil.get_terminal_size()</span></tt></a> is the high-level function which
should normally be used, <tt class="docutils literal"><span class="pre">os.get_terminal_size</span></tt> is the low-level
implementation.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="class">
<dt id="os.terminal_size">
<em class="property">class </em><tt class="descclassname">os.</tt><tt class="descname">terminal_size</tt><a class="headerlink" href="#os.terminal_size" title="Permalink to this definition">¶</a></dt>
<dd><p>A subclass of tuple, holding <tt class="docutils literal"><span class="pre">(columns,</span> <span class="pre">lines)</span></tt> of the terminal window size.</p>
<dl class="attribute">
<dt id="os.terminal_size.columns">
<tt class="descname">columns</tt><a class="headerlink" href="#os.terminal_size.columns" title="Permalink to this definition">¶</a></dt>
<dd><p>Width of the terminal window in characters.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.terminal_size.lines">
<tt class="descname">lines</tt><a class="headerlink" href="#os.terminal_size.lines" title="Permalink to this definition">¶</a></dt>
<dd><p>Height of the terminal window in characters.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="inheritance-of-file-descriptors">
<span id="fd-inheritance"></span><h3>16.1.4.2. Inheritance of File Descriptors<a class="headerlink" href="#inheritance-of-file-descriptors" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.4.</span></p>
</div>
<p>A file descriptor has an &#8220;inheritable&#8221; flag which indicates if the file descriptor
can be inherited by child processes.  Since Python 3.4, file descriptors
created by Python are non-inheritable by default.</p>
<p>On UNIX, non-inheritable file descriptors are closed in child processes at the
execution of a new program, other file descriptors are inherited.</p>
<p>On Windows, non-inheritable handles and file descriptors are closed in child
processes, except for standard streams (file descriptors 0, 1 and 2: stdin, stdout
and stderr), which are always inherited.  Using <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> functions,
all inheritable handles and all inheritable file descriptors are inherited.
Using the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module, all file descriptors except standard
streams are closed, and inheritable handles are only inherited if the
<em>close_fds</em> parameter is <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<dl class="function">
<dt id="os.get_inheritable">
<tt class="descclassname">os.</tt><tt class="descname">get_inheritable</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.get_inheritable" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the &#8220;inheritable&#8221; flag of the specified file descriptor (a boolean).</p>
</dd></dl>

<dl class="function">
<dt id="os.set_inheritable">
<tt class="descclassname">os.</tt><tt class="descname">set_inheritable</tt><big>(</big><em>fd</em>, <em>inheritable</em><big>)</big><a class="headerlink" href="#os.set_inheritable" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the &#8220;inheritable&#8221; flag of the specified file descriptor.</p>
</dd></dl>

<dl class="function">
<dt id="os.get_handle_inheritable">
<tt class="descclassname">os.</tt><tt class="descname">get_handle_inheritable</tt><big>(</big><em>handle</em><big>)</big><a class="headerlink" href="#os.get_handle_inheritable" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the &#8220;inheritable&#8221; flag of the specified handle (a boolean).</p>
<p>Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.set_handle_inheritable">
<tt class="descclassname">os.</tt><tt class="descname">set_handle_inheritable</tt><big>(</big><em>handle</em>, <em>inheritable</em><big>)</big><a class="headerlink" href="#os.set_handle_inheritable" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the &#8220;inheritable&#8221; flag of the specified handle.</p>
<p>Availability: Windows.</p>
</dd></dl>

</div>
</div>
<div class="section" id="files-and-directories">
<span id="os-file-dir"></span><h2>16.1.5. Files and Directories<a class="headerlink" href="#files-and-directories" title="Permalink to this headline">¶</a></h2>
<p>On some Unix platforms, many of these functions support one or more of these
features:</p>
<ul id="path-fd">
<li><p class="first"><strong>specifying a file descriptor:</strong>
For some functions, the <em>path</em> argument can be not only a string giving a path
name, but also a file descriptor.  The function will then operate on the file
referred to by the descriptor.  (For POSIX systems, Python will call the
<tt class="docutils literal"><span class="pre">f...</span></tt> version of the function.)</p>
<p>You can check whether or not <em>path</em> can be specified as a file descriptor on
your platform using <a class="reference internal" href="#os.supports_fd" title="os.supports_fd"><tt class="xref py py-data docutils literal"><span class="pre">os.supports_fd</span></tt></a>.  If it is unavailable, using it
will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a>.</p>
<p>If the function also supports <em>dir_fd</em> or <em>follow_symlinks</em> arguments, it is
an error to specify one of those when supplying <em>path</em> as a file descriptor.</p>
</li>
</ul>
<ul id="dir-fd">
<li><p class="first"><strong>paths relative to directory descriptors:</strong> If <em>dir_fd</em> is not <tt class="docutils literal"><span class="pre">None</span></tt>, it
should be a file descriptor referring to a directory, and the path to operate
on should be relative; path will then be relative to that directory.  If the
path is absolute, <em>dir_fd</em> is ignored.  (For POSIX systems, Python will call
the <tt class="docutils literal"><span class="pre">...at</span></tt> or <tt class="docutils literal"><span class="pre">f...at</span></tt> version of the function.)</p>
<p>You can check whether or not <em>dir_fd</em> is supported on your platform using
<a class="reference internal" href="#os.supports_dir_fd" title="os.supports_dir_fd"><tt class="xref py py-data docutils literal"><span class="pre">os.supports_dir_fd</span></tt></a>.  If it is unavailable, using it will raise a
<a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a>.</p>
</li>
</ul>
<ul id="follow-symlinks">
<li><p class="first"><strong>not following symlinks:</strong> If <em>follow_symlinks</em> is
<tt class="docutils literal"><span class="pre">False</span></tt>, and the last element of the path to operate on is a symbolic link,
the function will operate on the symbolic link itself instead of the file the
link points to.  (For POSIX systems, Python will call the <tt class="docutils literal"><span class="pre">l...</span></tt> version of
the function.)</p>
<p>You can check whether or not <em>follow_symlinks</em> is supported on your platform
using <a class="reference internal" href="#os.supports_follow_symlinks" title="os.supports_follow_symlinks"><tt class="xref py py-data docutils literal"><span class="pre">os.supports_follow_symlinks</span></tt></a>.  If it is unavailable, using it
will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a>.</p>
</li>
</ul>
<dl class="function">
<dt id="os.access">
<tt class="descclassname">os.</tt><tt class="descname">access</tt><big>(</big><em>path</em>, <em>mode</em>, <em>*</em>, <em>dir_fd=None</em>, <em>effective_ids=False</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.access" title="Permalink to this definition">¶</a></dt>
<dd><p>Use the real uid/gid to test for access to <em>path</em>.  Note that most operations
will use the effective uid/gid, therefore this routine can be used in a
suid/sgid environment to test if the invoking user has the specified access to
<em>path</em>.  <em>mode</em> should be <a class="reference internal" href="#os.F_OK" title="os.F_OK"><tt class="xref py py-const docutils literal"><span class="pre">F_OK</span></tt></a> to test the existence of <em>path</em>, or it
can be the inclusive OR of one or more of <a class="reference internal" href="#os.R_OK" title="os.R_OK"><tt class="xref py py-const docutils literal"><span class="pre">R_OK</span></tt></a>, <a class="reference internal" href="#os.W_OK" title="os.W_OK"><tt class="xref py py-const docutils literal"><span class="pre">W_OK</span></tt></a>, and
<a class="reference internal" href="#os.X_OK" title="os.X_OK"><tt class="xref py py-const docutils literal"><span class="pre">X_OK</span></tt></a> to test permissions.  Return <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const docutils literal"><span class="pre">True</span></tt></a> if access is allowed,
<a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const docutils literal"><span class="pre">False</span></tt></a> if not. See the Unix man page <em class="manpage">access(2)</em> for more
information.</p>
<p>This function can support specifying <a class="reference internal" href="#dir-fd"><em>paths relative to directory
descriptors</em></a> and <a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
<p>If <em>effective_ids</em> is <tt class="docutils literal"><span class="pre">True</span></tt>, <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> will perform its access
checks using the effective uid/gid instead of the real uid/gid.
<em>effective_ids</em> may not be supported on your platform; you can check whether
or not it is available using <a class="reference internal" href="#os.supports_effective_ids" title="os.supports_effective_ids"><tt class="xref py py-data docutils literal"><span class="pre">os.supports_effective_ids</span></tt></a>.  If it is
unavailable, using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Using <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to check if a user is authorized to e.g. open a file
before actually doing so using <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> creates a security hole,
because the user might exploit the short time interval between checking
and opening the file to manipulate it. It&#8217;s preferable to use <a class="reference internal" href="../glossary.html#term-eafp"><em class="xref std std-term">EAFP</em></a>
techniques. For example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="s">&quot;myfile&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">R_OK</span><span class="p">):</span>
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;myfile&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">return</span> <span class="s">&quot;some default data&quot;</span>
</pre></div>
</div>
<p>is better written as:</p>
<div class="last highlight-python3"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
    <span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;myfile&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">PermissionError</span><span class="p">:</span>
    <span class="k">return</span> <span class="s">&quot;some default data&quot;</span>
<span class="k">else</span><span class="p">:</span>
    <span class="k">with</span> <span class="n">fp</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">I/O operations may fail even when <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> indicates that they would
succeed, particularly for operations on network filesystems which may have
permissions semantics beyond the usual POSIX permission-bit model.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Added the <em>dir_fd</em>, <em>effective_ids</em>, and <em>follow_symlinks</em> parameters.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.F_OK">
<tt class="descclassname">os.</tt><tt class="descname">F_OK</tt><a class="headerlink" href="#os.F_OK" title="Permalink to this definition">¶</a></dt>
<dt id="os.R_OK">
<tt class="descclassname">os.</tt><tt class="descname">R_OK</tt><a class="headerlink" href="#os.R_OK" title="Permalink to this definition">¶</a></dt>
<dt id="os.W_OK">
<tt class="descclassname">os.</tt><tt class="descname">W_OK</tt><a class="headerlink" href="#os.W_OK" title="Permalink to this definition">¶</a></dt>
<dt id="os.X_OK">
<tt class="descclassname">os.</tt><tt class="descname">X_OK</tt><a class="headerlink" href="#os.X_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Values to pass as the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the
existence, readability, writability and executability of <em>path</em>,
respectively.</p>
</dd></dl>

<dl class="function">
<dt id="os.chdir">
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chdir" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-15">Change the current working directory to <em>path</em>.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>.  The
descriptor must refer to an opened directory, not an open file.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying <em>path</em> as a file descriptor
on some platforms.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chflags">
<tt class="descclassname">os.</tt><tt class="descname">chflags</tt><big>(</big><em>path</em>, <em>flags</em>, <em>*</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.chflags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination
(bitwise OR) of the following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module):</p>
<ul class="simple">
<li><a class="reference internal" href="stat.html#stat.UF_NODUMP" title="stat.UF_NODUMP"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NODUMP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_IMMUTABLE" title="stat.UF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_IMMUTABLE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_APPEND" title="stat.UF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_APPEND</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_OPAQUE" title="stat.UF_OPAQUE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_OPAQUE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_NOUNLINK" title="stat.UF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NOUNLINK</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_COMPRESSED" title="stat.UF_COMPRESSED"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_COMPRESSED</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_HIDDEN" title="stat.UF_HIDDEN"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_HIDDEN</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_ARCHIVED" title="stat.SF_ARCHIVED"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_ARCHIVED</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_IMMUTABLE" title="stat.SF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_IMMUTABLE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_APPEND" title="stat.SF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_APPEND</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_NOUNLINK" title="stat.SF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_NOUNLINK</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_SNAPSHOT" title="stat.SF_SNAPSHOT"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_SNAPSHOT</span></tt></a></li>
</ul>
<p>This function can support <a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>follow_symlinks</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chmod">
<tt class="descclassname">os.</tt><tt class="descname">chmod</tt><big>(</big><em>path</em>, <em>mode</em>, <em>*</em>, <em>dir_fd=None</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.chmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one of the
following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module) or bitwise ORed
combinations of them:</p>
<ul class="simple">
<li><a class="reference internal" href="stat.html#stat.S_ISUID" title="stat.S_ISUID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISUID</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ISGID" title="stat.S_ISGID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISGID</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ENFMT" title="stat.S_ENFMT"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ENFMT</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ISVTX" title="stat.S_ISVTX"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISVTX</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IREAD" title="stat.S_IREAD"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IREAD</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWRITE" title="stat.S_IWRITE"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWRITE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IEXEC" title="stat.S_IEXEC"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IEXEC</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXU" title="stat.S_IRWXU"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXU</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRUSR" title="stat.S_IRUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWUSR" title="stat.S_IWUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXUSR" title="stat.S_IXUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXG" title="stat.S_IRWXG"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXG</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRGRP" title="stat.S_IRGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWGRP" title="stat.S_IWGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXGRP" title="stat.S_IXGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXO" title="stat.S_IRWXO"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXO</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IROTH" title="stat.S_IROTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IROTH</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWOTH" title="stat.S_IWOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWOTH</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXOTH" title="stat.S_IXOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXOTH</span></tt></a></li>
</ul>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>,
<a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a> and <a class="reference internal" href="#follow-symlinks"><em>not
following symlinks</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Although Windows supports <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>, you can only set the file&#8217;s
read-only flag with it (via the <tt class="docutils literal"><span class="pre">stat.S_IWRITE</span></tt> and <tt class="docutils literal"><span class="pre">stat.S_IREAD</span></tt>
constants or a corresponding integer value).  All other bits are ignored.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor,
and the <em>dir_fd</em> and <em>follow_symlinks</em> arguments.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chown">
<tt class="descclassname">os.</tt><tt class="descname">chown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em>, <em>*</em>, <em>dir_fd=None</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.chown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>.  To
leave one of the ids unchanged, set it to -1.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>,
<a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a> and <a class="reference internal" href="#follow-symlinks"><em>not
following symlinks</em></a>.</p>
<p>See <a class="reference internal" href="shutil.html#shutil.chown" title="shutil.chown"><tt class="xref py py-func docutils literal"><span class="pre">shutil.chown()</span></tt></a> for a higher-level function that accepts names in
addition to numeric ids.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying an open file descriptor for <em>path</em>,
and the <em>dir_fd</em> and <em>follow_symlinks</em> arguments.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chroot">
<tt class="descclassname">os.</tt><tt class="descname">chroot</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chroot" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the root directory of the current process to <em>path</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchdir">
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fchdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the current working directory to the directory represented by the file
descriptor <em>fd</em>.  The descriptor must refer to an opened directory, not an
open file.  As of Python 3.3, this is equivalent to <tt class="docutils literal"><span class="pre">os.chdir(fd)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getcwd">
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwd" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string representing the current working directory.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getcwdb">
<tt class="descclassname">os.</tt><tt class="descname">getcwdb</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwdb" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a bytestring representing the current working directory.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchflags">
<tt class="descclassname">os.</tt><tt class="descname">lchflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.lchflags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>, like <a class="reference internal" href="#os.chflags" title="os.chflags"><tt class="xref py py-func docutils literal"><span class="pre">chflags()</span></tt></a>, but do
not follow symbolic links.  As of Python 3.3, this is equivalent to
<tt class="docutils literal"><span class="pre">os.chflags(path,</span> <span class="pre">flags,</span> <span class="pre">follow_symlinks=False)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchmod">
<tt class="descclassname">os.</tt><tt class="descname">lchmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.lchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this
affects the symlink rather than the target.  See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>
for possible values of <em>mode</em>.  As of Python 3.3, this is equivalent to
<tt class="docutils literal"><span class="pre">os.chmod(path,</span> <span class="pre">mode,</span> <span class="pre">follow_symlinks=False)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchown">
<tt class="descclassname">os.</tt><tt class="descname">lchown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.lchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>.  This
function will not follow symbolic links.  As of Python 3.3, this is equivalent
to <tt class="docutils literal"><span class="pre">os.chown(path,</span> <span class="pre">uid,</span> <span class="pre">gid,</span> <span class="pre">follow_symlinks=False)</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.link">
<tt class="descclassname">os.</tt><tt class="descname">link</tt><big>(</big><em>src</em>, <em>dst</em>, <em>*</em>, <em>src_dir_fd=None</em>, <em>dst_dir_fd=None</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.link" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a hard link pointing to <em>src</em> named <em>dst</em>.</p>
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
supply <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>, and <a class="reference internal" href="#follow-symlinks"><em>not
following symlinks</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>Added Windows support.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added the <em>src_dir_fd</em>, <em>dst_dir_fd</em>, and <em>follow_symlinks</em> arguments.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.listdir">
<tt class="descclassname">os.</tt><tt class="descname">listdir</tt><big>(</big><em>path='.'</em><big>)</big><a class="headerlink" href="#os.listdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list containing the names of the entries in the directory given by
<em>path</em>.  The list is in arbitrary order, and does not include the special
entries <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt> even if they are present in the directory.</p>
<p><em>path</em> may be either of type <tt class="docutils literal"><span class="pre">str</span></tt> or of type <tt class="docutils literal"><span class="pre">bytes</span></tt>.  If <em>path</em>
is of type <tt class="docutils literal"><span class="pre">bytes</span></tt>, the filenames returned will also be of type <tt class="docutils literal"><span class="pre">bytes</span></tt>;
in all other circumstances, they will be of type <tt class="docutils literal"><span class="pre">str</span></tt>.</p>
<p>This function can also support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>; the file descriptor must refer to a directory.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To encode <tt class="docutils literal"><span class="pre">str</span></tt> filenames to <tt class="docutils literal"><span class="pre">bytes</span></tt>, use <a class="reference internal" href="#os.fsencode" title="os.fsencode"><tt class="xref py py-func docutils literal"><span class="pre">fsencode()</span></tt></a>.</p>
</div>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>The <em>path</em> parameter became optional.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying an open file descriptor for <em>path</em>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.lstat">
<tt class="descclassname">os.</tt><tt class="descname">lstat</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.lstat" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform the equivalent of an <tt class="xref c c-func docutils literal"><span class="pre">lstat()</span></tt> system call on the given path.
Similar to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>, but does not follow symbolic links. Return a
<a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a> object.</p>
<p>On platforms that do not support symbolic links, this is an alias for
<a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p>
<p>As of Python 3.3, this is equivalent to <tt class="docutils literal"><span class="pre">os.stat(path,</span> <span class="pre">dir_fd=dir_fd,</span>
<span class="pre">follow_symlinks=False)</span></tt>.</p>
<p>This function can also support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> function.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.mkdir">
<tt class="descclassname">os.</tt><tt class="descname">mkdir</tt><big>(</big><em>path</em>, <em>mode=0o777</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.mkdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>.</p>
<p>On some systems, <em>mode</em> is ignored.  Where it is used, the current umask
value is first masked out.  If the directory already exists, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a>
is raised.</p>
<p>This function can also support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>It is also possible to create temporary directories; see the
<a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a> module&#8217;s <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><tt class="xref py py-func docutils literal"><span class="pre">tempfile.mkdtemp()</span></tt></a> function.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.makedirs">
<tt class="descclassname">os.</tt><tt class="descname">makedirs</tt><big>(</big><em>name</em>, <em>mode=0o777</em>, <em>exist_ok=False</em><big>)</big><a class="headerlink" href="#os.makedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-16">Recursive directory creation function.  Like <a class="reference internal" href="#os.mkdir" title="os.mkdir"><tt class="xref py py-func docutils literal"><span class="pre">mkdir()</span></tt></a>, but makes all
intermediate-level directories needed to contain the leaf directory.</p>
<p>The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0o777</span></tt> (octal).  On some systems, <em>mode</em> is
ignored.  Where it is used, the current umask value is first masked out.</p>
<p>If <em>exist_ok</em> is <tt class="docutils literal"><span class="pre">False</span></tt> (the default), an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised if the
target directory already exists.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a class="reference internal" href="#os.makedirs" title="os.makedirs"><tt class="xref py py-func docutils literal"><span class="pre">makedirs()</span></tt></a> will become confused if the path elements to create
include <a class="reference internal" href="#os.pardir" title="os.pardir"><tt class="xref py py-data docutils literal"><span class="pre">pardir</span></tt></a> (eg. &#8221;..&#8221; on UNIX systems).</p>
</div>
<p>This function handles UNC paths correctly.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2: </span>The <em>exist_ok</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4.1: </span>Before Python 3.4.1, if <em>exist_ok</em> was <tt class="docutils literal"><span class="pre">True</span></tt> and the directory existed,
<a class="reference internal" href="#os.makedirs" title="os.makedirs"><tt class="xref py py-func docutils literal"><span class="pre">makedirs()</span></tt></a> would still raise an error if <em>mode</em> did not match the
mode of the existing directory. Since this behavior was impossible to
implement safely, it was removed in Python 3.4.1. See <a class="reference external" href="https://bugs.python.org/issue21082">issue 21082</a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.mkfifo">
<tt class="descclassname">os.</tt><tt class="descname">mkfifo</tt><big>(</big><em>path</em>, <em>mode=0o666</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.mkfifo" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>.
The current umask value is first masked out from the mode.</p>
<p>This function can also support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>FIFOs are pipes that can be accessed like regular files.  FIFOs exist until they
are deleted (for example with <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">os.unlink()</span></tt></a>). Generally, FIFOs are used as
rendezvous between &#8220;client&#8221; and &#8220;server&#8221; type processes: the server opens the
FIFO for reading, and the client opens it for writing.  Note that <a class="reference internal" href="#os.mkfifo" title="os.mkfifo"><tt class="xref py py-func docutils literal"><span class="pre">mkfifo()</span></tt></a>
doesn&#8217;t open the FIFO &#8212; it just creates the rendezvous point.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.mknod">
<tt class="descclassname">os.</tt><tt class="descname">mknod</tt><big>(</big><em>filename</em>, <em>mode=0o600</em>, <em>device=0</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.mknod" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a filesystem node (file, device special file or named pipe) named
<em>filename</em>. <em>mode</em> specifies both the permissions to use and the type of node
to be created, being combined (bitwise OR) with one of <tt class="docutils literal"><span class="pre">stat.S_IFREG</span></tt>,
<tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt>, <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>, and <tt class="docutils literal"><span class="pre">stat.S_IFIFO</span></tt> (those constants are
available in <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a>).  For <tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt> and <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>,
<em>device</em> defines the newly created device special file (probably using
<a class="reference internal" href="#os.makedev" title="os.makedev"><tt class="xref py py-func docutils literal"><span class="pre">os.makedev()</span></tt></a>), otherwise it is ignored.</p>
<p>This function can also support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.major">
<tt class="descclassname">os.</tt><tt class="descname">major</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.major" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device major number from a raw device number (usually the
<tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p>
</dd></dl>

<dl class="function">
<dt id="os.minor">
<tt class="descclassname">os.</tt><tt class="descname">minor</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.minor" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device minor number from a raw device number (usually the
<tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p>
</dd></dl>

<dl class="function">
<dt id="os.makedev">
<tt class="descclassname">os.</tt><tt class="descname">makedev</tt><big>(</big><em>major</em>, <em>minor</em><big>)</big><a class="headerlink" href="#os.makedev" title="Permalink to this definition">¶</a></dt>
<dd><p>Compose a raw device number from the major and minor device numbers.</p>
</dd></dl>

<dl class="function">
<dt id="os.pathconf">
<tt class="descclassname">os.</tt><tt class="descname">pathconf</tt><big>(</big><em>path</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.pathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to a named file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.pathconf_names">
<tt class="descclassname">os.</tt><tt class="descname">pathconf_names</tt><a class="headerlink" href="#os.pathconf_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.pathconf" title="os.pathconf"><tt class="xref py py-func docutils literal"><span class="pre">pathconf()</span></tt></a> and <a class="reference internal" href="#os.fpathconf" title="os.fpathconf"><tt class="xref py py-func docutils literal"><span class="pre">fpathconf()</span></tt></a> to
the integer values defined for those names by the host operating system.  This
can be used to determine the set of names known to the system.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.readlink">
<tt class="descclassname">os.</tt><tt class="descname">readlink</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.readlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string representing the path to which the symbolic link points.  The
result may be either an absolute or relative pathname; if it is relative, it
may be converted to an absolute pathname using
<tt class="docutils literal"><span class="pre">os.path.join(os.path.dirname(path),</span> <span class="pre">result)</span></tt>.</p>
<p>If the <em>path</em> is a string object, the result will also be a string object,
and the call may raise an UnicodeDecodeError. If the <em>path</em> is a bytes
object, the result will be a bytes object.</p>
<p>This function can also support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>Availability: Unix, Windows</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.remove">
<tt class="descclassname">os.</tt><tt class="descname">remove</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.remove" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the file <em>path</em>.  If <em>path</em> is a directory, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is
raised.  Use <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> to remove directories.</p>
<p>This function can support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>On Windows, attempting to remove a file that is in use causes an exception to
be raised; on Unix, the directory entry is removed but the storage allocated
to the file is not made available until the original file is no longer in use.</p>
<p>This function is identical to <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.removedirs">
<tt class="descclassname">os.</tt><tt class="descname">removedirs</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.removedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-17">Remove directories recursively.  Works like <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> except that, if the
leaf directory is successfully removed, <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a>  tries to
successively remove every parent directory mentioned in  <em>path</em> until an error
is raised (which is ignored, because it generally means that a parent directory
is not empty). For example, <tt class="docutils literal"><span class="pre">os.removedirs('foo/bar/baz')</span></tt> will first remove
the directory <tt class="docutils literal"><span class="pre">'foo/bar/baz'</span></tt>, and then remove <tt class="docutils literal"><span class="pre">'foo/bar'</span></tt> and <tt class="docutils literal"><span class="pre">'foo'</span></tt> if
they are empty. Raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the leaf directory could not be
successfully removed.</p>
</dd></dl>

<dl class="function">
<dt id="os.rename">
<tt class="descclassname">os.</tt><tt class="descname">rename</tt><big>(</big><em>src</em>, <em>dst</em>, <em>*</em>, <em>src_dir_fd=None</em>, <em>dst_dir_fd=None</em><big>)</big><a class="headerlink" href="#os.rename" title="Permalink to this definition">¶</a></dt>
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>.  If <em>dst</em> is a directory,
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised.  On Unix, if <em>dst</em> exists and is a file, it will
be replaced silently if the user has permission.  The operation may fail on some
Unix flavors if <em>src</em> and <em>dst</em> are on different filesystems.  If successful,
the renaming will be an atomic operation (this is a POSIX requirement).  On
Windows, if <em>dst</em> already exists, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised even if it is a
file.</p>
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
supply <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>If you want cross-platform overwriting of the destination, use <a class="reference internal" href="#os.replace" title="os.replace"><tt class="xref py py-func docutils literal"><span class="pre">replace()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>src_dir_fd</em> and <em>dst_dir_fd</em> arguments.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.renames">
<tt class="descclassname">os.</tt><tt class="descname">renames</tt><big>(</big><em>old</em>, <em>new</em><big>)</big><a class="headerlink" href="#os.renames" title="Permalink to this definition">¶</a></dt>
<dd><p>Recursive directory or file renaming function. Works like <a class="reference internal" href="#os.rename" title="os.rename"><tt class="xref py py-func docutils literal"><span class="pre">rename()</span></tt></a>, except
creation of any intermediate directories needed to make the new pathname good is
attempted first. After the rename, directories corresponding to rightmost path
segments of the old name will be pruned away using <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function can fail with the new directory structure made if you lack
permissions needed to remove the leaf directory or file.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.replace">
<tt class="descclassname">os.</tt><tt class="descname">replace</tt><big>(</big><em>src</em>, <em>dst</em>, <em>*</em>, <em>src_dir_fd=None</em>, <em>dst_dir_fd=None</em><big>)</big><a class="headerlink" href="#os.replace" title="Permalink to this definition">¶</a></dt>
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>.  If <em>dst</em> is a directory,
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised.  If <em>dst</em> exists and is a file, it will
be replaced silently if the user has permission.  The operation may fail
if <em>src</em> and <em>dst</em> are on different filesystems.  If successful,
the renaming will be an atomic operation (this is a POSIX requirement).</p>
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
supply <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.rmdir">
<tt class="descclassname">os.</tt><tt class="descname">rmdir</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.rmdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the directory <em>path</em>.  Only works when the directory is
empty, otherwise, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.  In order to remove whole
directory trees, <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><tt class="xref py py-func docutils literal"><span class="pre">shutil.rmtree()</span></tt></a> can be used.</p>
<p>This function can support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> parameter.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.stat">
<tt class="descclassname">os.</tt><tt class="descname">stat</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.stat" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the status of a file or a file descriptor. Perform the equivalent of a
<tt class="xref c c-func docutils literal"><span class="pre">stat()</span></tt> system call on the given path. <em>path</em> may be specified as
either a string or as an open file descriptor. Return a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a>
object.</p>
<p>This function normally follows symlinks; to stat a symlink add the argument
<tt class="docutils literal"><span class="pre">follow_symlinks=False</span></tt>, or use <a class="reference internal" href="#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a>.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a> and
<a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
<p id="index-18">Example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s">&#39;somefile.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span>
<span class="go">os.stat_result(st_mode=33188, st_ino=7876932, st_dev=234881026,</span>
<span class="go">st_nlink=1, st_uid=501, st_gid=501, st_size=264, st_atime=1297230295,</span>
<span class="go">st_mtime=1297230027, st_ctime=1297230027)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span>
<span class="go">264</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#os.fstat" title="os.fstat"><tt class="xref py py-func docutils literal"><span class="pre">fstat()</span></tt></a> and <a class="reference internal" href="#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a> functions.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added the <em>dir_fd</em> and <em>follow_symlinks</em> arguments, specifying a file
descriptor instead of a path.</p>
</div>
</dd></dl>

<dl class="class">
<dt id="os.stat_result">
<em class="property">class </em><tt class="descclassname">os.</tt><tt class="descname">stat_result</tt><a class="headerlink" href="#os.stat_result" title="Permalink to this definition">¶</a></dt>
<dd><p>Object whose attributes correspond roughly to the members of the
<tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure. It is used for the result of <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">os.stat()</span></tt></a>,
<a class="reference internal" href="#os.fstat" title="os.fstat"><tt class="xref py py-func docutils literal"><span class="pre">os.fstat()</span></tt></a> and <a class="reference internal" href="#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">os.lstat()</span></tt></a>.</p>
<p>Attributes:</p>
<dl class="attribute">
<dt id="os.stat_result.st_mode">
<tt class="descname">st_mode</tt><a class="headerlink" href="#os.stat_result.st_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>File mode: file type and file mode bits (permissions).</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_ino">
<tt class="descname">st_ino</tt><a class="headerlink" href="#os.stat_result.st_ino" title="Permalink to this definition">¶</a></dt>
<dd><p>Inode number.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_dev">
<tt class="descname">st_dev</tt><a class="headerlink" href="#os.stat_result.st_dev" title="Permalink to this definition">¶</a></dt>
<dd><p>Identifier of the device on which this file resides.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_nlink">
<tt class="descname">st_nlink</tt><a class="headerlink" href="#os.stat_result.st_nlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of hard links.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_uid">
<tt class="descname">st_uid</tt><a class="headerlink" href="#os.stat_result.st_uid" title="Permalink to this definition">¶</a></dt>
<dd><p>User identifier of the file owner.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_gid">
<tt class="descname">st_gid</tt><a class="headerlink" href="#os.stat_result.st_gid" title="Permalink to this definition">¶</a></dt>
<dd><p>Group identifier of the file owner.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_size">
<tt class="descname">st_size</tt><a class="headerlink" href="#os.stat_result.st_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Size of the file in bytes, if it is a regular file or a symbolic link.
The size of a symbolic link is the length of the pathname it contains,
without a terminating null byte.</p>
</dd></dl>

<p>Timestamps:</p>
<dl class="attribute">
<dt id="os.stat_result.st_atime">
<tt class="descname">st_atime</tt><a class="headerlink" href="#os.stat_result.st_atime" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of most recent access expressed in seconds.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_mtime">
<tt class="descname">st_mtime</tt><a class="headerlink" href="#os.stat_result.st_mtime" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of most recent content modification expressed in seconds.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_ctime">
<tt class="descname">st_ctime</tt><a class="headerlink" href="#os.stat_result.st_ctime" title="Permalink to this definition">¶</a></dt>
<dd><p>Platform dependent:</p>
<ul class="simple">
<li>the time of most recent metadata change on Unix,</li>
<li>the time of creation on Windows, expressed in seconds.</li>
</ul>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_atime_ns">
<tt class="descname">st_atime_ns</tt><a class="headerlink" href="#os.stat_result.st_atime_ns" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of most recent access expressed in nanoseconds as an integer.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_mtime_ns">
<tt class="descname">st_mtime_ns</tt><a class="headerlink" href="#os.stat_result.st_mtime_ns" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of most recent content modification expressed in nanoseconds as an
integer.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_ctime_ns">
<tt class="descname">st_ctime_ns</tt><a class="headerlink" href="#os.stat_result.st_ctime_ns" title="Permalink to this definition">¶</a></dt>
<dd><p>Platform dependent:</p>
<ul class="simple">
<li>the time of most recent metadata change on Unix,</li>
<li>the time of creation on Windows, expressed in nanoseconds as an
integer.</li>
</ul>
</dd></dl>

<p>See also the <a class="reference internal" href="#os.stat_float_times" title="os.stat_float_times"><tt class="xref py py-func docutils literal"><span class="pre">stat_float_times()</span></tt></a> function.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>The exact meaning and resolution of the <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt></a>,
<a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt></a>, and <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt></a> attributes depend on the operating
system and the file system. For example, on Windows systems using the FAT
or FAT32 file systems, <a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt></a> has 2-second resolution, and
<a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt></a> has only 1-day resolution.  See your operating system
documentation for details.</p>
<p class="last">Similarly, although <a class="reference internal" href="#os.stat_result.st_atime_ns" title="os.stat_result.st_atime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime_ns</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_mtime_ns" title="os.stat_result.st_mtime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime_ns</span></tt></a>,
and <a class="reference internal" href="#os.stat_result.st_ctime_ns" title="os.stat_result.st_ctime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime_ns</span></tt></a> are always expressed in nanoseconds, many
systems do not provide nanosecond precision.  On systems that do
provide nanosecond precision, the floating-point object used to
store <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt></a>, and <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt></a>
cannot preserve all of it, and as such will be slightly inexact.
If you need the exact timestamps you should always use
<a class="reference internal" href="#os.stat_result.st_atime_ns" title="os.stat_result.st_atime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime_ns</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_mtime_ns" title="os.stat_result.st_mtime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime_ns</span></tt></a>, and <a class="reference internal" href="#os.stat_result.st_ctime_ns" title="os.stat_result.st_ctime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime_ns</span></tt></a>.</p>
</div>
<p>On some Unix systems (such as Linux), the following attributes may also be
available:</p>
<dl class="attribute">
<dt id="os.stat_result.st_blocks">
<tt class="descname">st_blocks</tt><a class="headerlink" href="#os.stat_result.st_blocks" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of 512-byte blocks allocated for file.
This may be smaller than <a class="reference internal" href="#os.stat_result.st_size" title="os.stat_result.st_size"><tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt></a>/512 when the file has holes.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_blksize">
<tt class="descname">st_blksize</tt><a class="headerlink" href="#os.stat_result.st_blksize" title="Permalink to this definition">¶</a></dt>
<dd><p>&#8220;Preferred&#8221; blocksize for efficient file system I/O. Writing to a file in
smaller chunks may cause an inefficient read-modify-rewrite.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_rdev">
<tt class="descname">st_rdev</tt><a class="headerlink" href="#os.stat_result.st_rdev" title="Permalink to this definition">¶</a></dt>
<dd><p>Type of device if an inode device.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_flags">
<tt class="descname">st_flags</tt><a class="headerlink" href="#os.stat_result.st_flags" title="Permalink to this definition">¶</a></dt>
<dd><p>User defined flags for file.</p>
</dd></dl>

<p>On other Unix systems (such as FreeBSD), the following attributes may be
available (but may be only filled out if root tries to use them):</p>
<dl class="attribute">
<dt id="os.stat_result.st_gen">
<tt class="descname">st_gen</tt><a class="headerlink" href="#os.stat_result.st_gen" title="Permalink to this definition">¶</a></dt>
<dd><p>File generation number.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_birthtime">
<tt class="descname">st_birthtime</tt><a class="headerlink" href="#os.stat_result.st_birthtime" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of file creation.</p>
</dd></dl>

<p>On Mac OS systems, the following attributes may also be available:</p>
<dl class="attribute">
<dt id="os.stat_result.st_rsize">
<tt class="descname">st_rsize</tt><a class="headerlink" href="#os.stat_result.st_rsize" title="Permalink to this definition">¶</a></dt>
<dd><p>Real size of the file.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_creator">
<tt class="descname">st_creator</tt><a class="headerlink" href="#os.stat_result.st_creator" title="Permalink to this definition">¶</a></dt>
<dd><p>Creator of the file.</p>
</dd></dl>

<dl class="attribute">
<dt id="os.stat_result.st_type">
<tt class="descname">st_type</tt><a class="headerlink" href="#os.stat_result.st_type" title="Permalink to this definition">¶</a></dt>
<dd><p>File type.</p>
</dd></dl>

<p>The standard module <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> defines functions and constants that are
useful for extracting information from a <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure. (On
Windows, some items are filled with dummy values.)</p>
<p>For backward compatibility, a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a> instance is also
accessible as a tuple of at least 10 integers giving the most important (and
portable) members of the <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure, in the order
<a class="reference internal" href="#os.stat_result.st_mode" title="os.stat_result.st_mode"><tt class="xref py py-attr docutils literal"><span class="pre">st_mode</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_ino" title="os.stat_result.st_ino"><tt class="xref py py-attr docutils literal"><span class="pre">st_ino</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_dev" title="os.stat_result.st_dev"><tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_nlink" title="os.stat_result.st_nlink"><tt class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></tt></a>,
<a class="reference internal" href="#os.stat_result.st_uid" title="os.stat_result.st_uid"><tt class="xref py py-attr docutils literal"><span class="pre">st_uid</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_gid" title="os.stat_result.st_gid"><tt class="xref py py-attr docutils literal"><span class="pre">st_gid</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_size" title="os.stat_result.st_size"><tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt></a>,
<a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt></a>. More items may be added at the end by
some implementations. For compatibility with older Python versions,
accessing <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a> as a tuple always returns integers.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added the <a class="reference internal" href="#os.stat_result.st_atime_ns" title="os.stat_result.st_atime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_atime_ns</span></tt></a>, <a class="reference internal" href="#os.stat_result.st_mtime_ns" title="os.stat_result.st_mtime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime_ns</span></tt></a>, and
<a class="reference internal" href="#os.stat_result.st_ctime_ns" title="os.stat_result.st_ctime_ns"><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime_ns</span></tt></a> members.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.stat_float_times">
<tt class="descclassname">os.</tt><tt class="descname">stat_float_times</tt><big>(</big><span class="optional">[</span><em>newvalue</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.stat_float_times" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine whether <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a> represents time stamps as float objects.
If <em>newvalue</em> is <tt class="docutils literal"><span class="pre">True</span></tt>, future calls to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> return floats, if it is
<tt class="docutils literal"><span class="pre">False</span></tt>, future calls return ints. If <em>newvalue</em> is omitted, return the
current setting.</p>
<p>For compatibility with older Python versions, accessing <a class="reference internal" href="#os.stat_result" title="os.stat_result"><tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt></a> as
a tuple always returns integers.</p>
<p>Python now returns float values by default. Applications which do not work
correctly with floating point time stamps can use this function to restore the
old behaviour.</p>
<p>The resolution of the timestamps (that is the smallest possible fraction)
depends on the system. Some systems only support second resolution; on these
systems, the fraction will always be zero.</p>
<p>It is recommended that this setting is only changed at program startup time in
the <em>__main__</em> module; libraries should never change this setting. If an
application uses a library that works incorrectly if floating point time stamps
are processed, this application should turn the feature off until the library
has been corrected.</p>
<div class="deprecated">
<p><span class="versionmodified">Deprecated since version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.statvfs">
<tt class="descclassname">os.</tt><tt class="descname">statvfs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.statvfs" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a <tt class="xref c c-func docutils literal"><span class="pre">statvfs()</span></tt> system call on the given path.  The return value is
an object whose attributes describe the filesystem on the given path, and
correspond to the members of the <tt class="xref c c-type docutils literal"><span class="pre">statvfs</span></tt> structure, namely:
<tt class="xref py py-attr docutils literal"><span class="pre">f_bsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_frsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_blocks</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_bfree</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">f_bavail</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_files</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_ffree</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_favail</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">f_flag</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_namemax</span></tt>.</p>
<p>Two module-level constants are defined for the <tt class="xref py py-attr docutils literal"><span class="pre">f_flag</span></tt> attribute&#8217;s
bit-flags: if <tt class="xref py py-const docutils literal"><span class="pre">ST_RDONLY</span></tt> is set, the filesystem is mounted
read-only, and if <tt class="xref py py-const docutils literal"><span class="pre">ST_NOSUID</span></tt> is set, the semantics of
setuid/setgid bits are disabled or not supported.</p>
<p>Additional module-level constants are defined for GNU/glibc based systems.
These are <tt class="xref py py-const docutils literal"><span class="pre">ST_NODEV</span></tt> (disallow access to device special files),
<tt class="xref py py-const docutils literal"><span class="pre">ST_NOEXEC</span></tt> (disallow program execution), <tt class="xref py py-const docutils literal"><span class="pre">ST_SYNCHRONOUS</span></tt>
(writes are synced at once), <tt class="xref py py-const docutils literal"><span class="pre">ST_MANDLOCK</span></tt> (allow mandatory locks on an FS),
<tt class="xref py py-const docutils literal"><span class="pre">ST_WRITE</span></tt> (write on file/directory/symlink), <tt class="xref py py-const docutils literal"><span class="pre">ST_APPEND</span></tt>
(append-only file), <tt class="xref py py-const docutils literal"><span class="pre">ST_IMMUTABLE</span></tt> (immutable file), <tt class="xref py py-const docutils literal"><span class="pre">ST_NOATIME</span></tt>
(do not update access times), <tt class="xref py py-const docutils literal"><span class="pre">ST_NODIRATIME</span></tt> (do not update directory access
times), <tt class="xref py py-const docutils literal"><span class="pre">ST_RELATIME</span></tt> (update atime relative to mtime/ctime).</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>The <tt class="xref py py-const docutils literal"><span class="pre">ST_RDONLY</span></tt> and <tt class="xref py py-const docutils literal"><span class="pre">ST_NOSUID</span></tt> constants were added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.4: </span>The <tt class="xref py py-const docutils literal"><span class="pre">ST_NODEV</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_NOEXEC</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_SYNCHRONOUS</span></tt>,
<tt class="xref py py-const docutils literal"><span class="pre">ST_MANDLOCK</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_WRITE</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_APPEND</span></tt>,
<tt class="xref py py-const docutils literal"><span class="pre">ST_IMMUTABLE</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_NOATIME</span></tt>, <tt class="xref py py-const docutils literal"><span class="pre">ST_NODIRATIME</span></tt>,
and <tt class="xref py py-const docutils literal"><span class="pre">ST_RELATIME</span></tt> constants were added.</p>
</div>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying an open file descriptor for <em>path</em>.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.supports_dir_fd">
<tt class="descclassname">os.</tt><tt class="descname">supports_dir_fd</tt><a class="headerlink" href="#os.supports_dir_fd" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="collections.abc.html#collections.abc.Set" title="collections.abc.Set"><tt class="xref py py-class docutils literal"><span class="pre">Set</span></tt></a> object indicating which functions in the
<a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module permit use of their <em>dir_fd</em> parameter.  Different platforms
provide different functionality, and an option that might work on one might
be unsupported on another.  For consistency&#8217;s sakes, functions that support
<em>dir_fd</em> always allow specifying the parameter, but will raise an exception
if the functionality is not actually available.</p>
<p>To check whether a particular function permits use of its <em>dir_fd</em>
parameter, use the <tt class="docutils literal"><span class="pre">in</span></tt> operator on <tt class="docutils literal"><span class="pre">supports_dir_fd</span></tt>.  As an example,
this expression determines whether the <em>dir_fd</em> parameter of <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">os.stat()</span></tt></a>
is locally available:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">os</span><span class="o">.</span><span class="n">stat</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_dir_fd</span>
</pre></div>
</div>
<p>Currently <em>dir_fd</em> parameters only work on Unix platforms; none of them work
on Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.supports_effective_ids">
<tt class="descclassname">os.</tt><tt class="descname">supports_effective_ids</tt><a class="headerlink" href="#os.supports_effective_ids" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="collections.abc.html#collections.abc.Set" title="collections.abc.Set"><tt class="xref py py-class docutils literal"><span class="pre">Set</span></tt></a> object indicating which functions in the
<a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module permit use of the <em>effective_ids</em> parameter for
<a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">os.access()</span></tt></a>.  If the local platform supports it, the collection will
contain <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">os.access()</span></tt></a>, otherwise it will be empty.</p>
<p>To check whether you can use the <em>effective_ids</em> parameter for
<a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">os.access()</span></tt></a>, use the <tt class="docutils literal"><span class="pre">in</span></tt> operator on <tt class="docutils literal"><span class="pre">supports_effective_ids</span></tt>,
like so:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">os</span><span class="o">.</span><span class="n">access</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_effective_ids</span>
</pre></div>
</div>
<p>Currently <em>effective_ids</em> only works on Unix platforms; it does not work on
Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.supports_fd">
<tt class="descclassname">os.</tt><tt class="descname">supports_fd</tt><a class="headerlink" href="#os.supports_fd" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="collections.abc.html#collections.abc.Set" title="collections.abc.Set"><tt class="xref py py-class docutils literal"><span class="pre">Set</span></tt></a> object indicating which functions in the
<a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module permit specifying their <em>path</em> parameter as an open file
descriptor.  Different platforms provide different functionality, and an
option that might work on one might be unsupported on another.  For
consistency&#8217;s sakes, functions that support <em>fd</em> always allow specifying
the parameter, but will raise an exception if the functionality is not
actually available.</p>
<p>To check whether a particular function permits specifying an open file
descriptor for its <em>path</em> parameter, use the <tt class="docutils literal"><span class="pre">in</span></tt> operator on
<tt class="docutils literal"><span class="pre">supports_fd</span></tt>. As an example, this expression determines whether
<a class="reference internal" href="#os.chdir" title="os.chdir"><tt class="xref py py-func docutils literal"><span class="pre">os.chdir()</span></tt></a> accepts open file descriptors when called on your local
platform:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">os</span><span class="o">.</span><span class="n">chdir</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_fd</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.supports_follow_symlinks">
<tt class="descclassname">os.</tt><tt class="descname">supports_follow_symlinks</tt><a class="headerlink" href="#os.supports_follow_symlinks" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="collections.abc.html#collections.abc.Set" title="collections.abc.Set"><tt class="xref py py-class docutils literal"><span class="pre">Set</span></tt></a> object indicating which functions in the
<a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module permit use of their <em>follow_symlinks</em> parameter.  Different
platforms provide different functionality, and an option that might work on
one might be unsupported on another.  For consistency&#8217;s sakes, functions that
support <em>follow_symlinks</em> always allow specifying the parameter, but will
raise an exception if the functionality is not actually available.</p>
<p>To check whether a particular function permits use of its <em>follow_symlinks</em>
parameter, use the <tt class="docutils literal"><span class="pre">in</span></tt> operator on <tt class="docutils literal"><span class="pre">supports_follow_symlinks</span></tt>.  As an
example, this expression determines whether the <em>follow_symlinks</em> parameter
of <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">os.stat()</span></tt></a> is locally available:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="n">os</span><span class="o">.</span><span class="n">stat</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_follow_symlinks</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.symlink">
<tt class="descclassname">os.</tt><tt class="descname">symlink</tt><big>(</big><em>source</em>, <em>link_name</em>, <em>target_is_directory=False</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.symlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a symbolic link pointing to <em>source</em> named <em>link_name</em>.</p>
<p>On Windows, a symlink represents either a file or a directory, and does not
morph to the target dynamically.  If the target is present, the type of the
symlink will be created to match. Otherwise, the symlink will be created
as a directory if <em>target_is_directory</em> is <tt class="docutils literal"><span class="pre">True</span></tt> or a file symlink (the
default) otherwise.  On non-Window platforms, <em>target_is_directory</em> is ignored.</p>
<p>Symbolic link support was introduced in Windows 6.0 (Vista).  <a class="reference internal" href="#os.symlink" title="os.symlink"><tt class="xref py py-func docutils literal"><span class="pre">symlink()</span></tt></a>
will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> on Windows versions earlier than 6.0.</p>
<p>This function can support <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>On Windows, the <em>SeCreateSymbolicLinkPrivilege</em> is required in order to
successfully create symlinks. This privilege is not typically granted to
regular users but is available to accounts which can escalate privileges
to the administrator level. Either obtaining the privilege or running your
application as an administrator are ways to successfully create symlinks.</p>
<p class="last"><a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised when the function is called by an unprivileged
user.</p>
</div>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added the <em>dir_fd</em> argument, and now allow <em>target_is_directory</em>
on non-Windows platforms.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.sync">
<tt class="descclassname">os.</tt><tt class="descname">sync</tt><big>(</big><big>)</big><a class="headerlink" href="#os.sync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of everything to disk.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.truncate">
<tt class="descclassname">os.</tt><tt class="descname">truncate</tt><big>(</big><em>path</em>, <em>length</em><big>)</big><a class="headerlink" href="#os.truncate" title="Permalink to this definition">¶</a></dt>
<dd><p>Truncate the file corresponding to <em>path</em>, so that it is at most
<em>length</em> bytes in size.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.unlink">
<tt class="descclassname">os.</tt><tt class="descname">unlink</tt><big>(</big><em>path</em>, <em>*</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.unlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the file <em>path</em>.  This function is identical to
<a class="reference internal" href="#os.remove" title="os.remove"><tt class="xref py py-func docutils literal"><span class="pre">remove()</span></tt></a>; the <tt class="docutils literal"><span class="pre">unlink</span></tt> name is its traditional Unix
name.  Please see the documentation for <a class="reference internal" href="#os.remove" title="os.remove"><tt class="xref py py-func docutils literal"><span class="pre">remove()</span></tt></a> for
further information.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>The <em>dir_fd</em> parameter.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.utime">
<tt class="descclassname">os.</tt><tt class="descname">utime</tt><big>(</big><em>path</em>, <em>times=None</em>, <em>*</em>, <em>ns=None</em>, <em>dir_fd=None</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.utime" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the access and modified times of the file specified by <em>path</em>.</p>
<p><a class="reference internal" href="#os.utime" title="os.utime"><tt class="xref py py-func docutils literal"><span class="pre">utime()</span></tt></a> takes two optional parameters, <em>times</em> and <em>ns</em>.
These specify the times set on <em>path</em> and are used as follows:</p>
<ul class="simple">
<li>If <em>ns</em> is not <tt class="docutils literal"><span class="pre">None</span></tt>,
it must be a 2-tuple of the form <tt class="docutils literal"><span class="pre">(atime_ns,</span> <span class="pre">mtime_ns)</span></tt>
where each member is an int expressing nanoseconds.</li>
<li>If <em>times</em> is not <tt class="docutils literal"><span class="pre">None</span></tt>,
it must be a 2-tuple of the form <tt class="docutils literal"><span class="pre">(atime,</span> <span class="pre">mtime)</span></tt>
where each member is an int or float expressing seconds.</li>
<li>If <em>times</em> and <em>ns</em> are both <tt class="docutils literal"><span class="pre">None</span></tt>,
this is equivalent to specifying <tt class="docutils literal"><span class="pre">ns=(atime_ns,</span> <span class="pre">mtime_ns)</span></tt>
where both times are the current time.</li>
</ul>
<p>It is an error to specify tuples for both <em>times</em> and <em>ns</em>.</p>
<p>Whether a directory can be given for <em>path</em>
depends on whether the operating system implements directories as files
(for example, Windows does not).  Note that the exact times you set here may
not be returned by a subsequent <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> call, depending on the
resolution with which your operating system records access and modification
times; see <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.  The best way to preserve exact times is to
use the <em>st_atime_ns</em> and <em>st_mtime_ns</em> fields from the <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">os.stat()</span></tt></a>
result object with the <em>ns</em> parameter to <cite>utime</cite>.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a>,
<a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a> and <a class="reference internal" href="#follow-symlinks"><em>not
following symlinks</em></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying an open file descriptor for <em>path</em>,
and the <em>dir_fd</em>, <em>follow_symlinks</em>, and <em>ns</em> parameters.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.walk">
<tt class="descclassname">os.</tt><tt class="descname">walk</tt><big>(</big><em>top</em>, <em>topdown=True</em>, <em>onerror=None</em>, <em>followlinks=False</em><big>)</big><a class="headerlink" href="#os.walk" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-19">Generate the file names in a directory tree by walking the tree
either top-down or bottom-up. For each directory in the tree rooted at directory
<em>top</em> (including <em>top</em> itself), it yields a 3-tuple <tt class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span>
<span class="pre">filenames)</span></tt>.</p>
<p><em>dirpath</em> is a string, the path to the directory.  <em>dirnames</em> is a list of the
names of the subdirectories in <em>dirpath</em> (excluding <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt>).
<em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>.
Note that the names in the lists contain no path components.  To get a full path
(which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do
<tt class="docutils literal"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></tt>.</p>
<p>If optional argument <em>topdown</em> is <tt class="docutils literal"><span class="pre">True</span></tt> or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top-down).  If <em>topdown</em> is <tt class="docutils literal"><span class="pre">False</span></tt>, the triple
for a directory is generated after the triples for all of its subdirectories
(directories are generated bottom-up). No matter the value of <em>topdown</em>, the
list of subdirectories is retrieved before the tuples for the directory and
its subdirectories are generated.</p>
<p>When <em>topdown</em> is <tt class="docutils literal"><span class="pre">True</span></tt>, the caller can modify the <em>dirnames</em> list in-place
(perhaps using <a class="reference internal" href="../reference/simple_stmts.html#del"><tt class="xref std std-keyword docutils literal"><span class="pre">del</span></tt></a> or slice assignment), and <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will only
recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be
used to prune the search, impose a specific order of visiting, or even to inform
<a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> about directories the caller creates or renames before it resumes
<a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> again.  Modifying <em>dirnames</em> when <em>topdown</em> is <tt class="docutils literal"><span class="pre">False</span></tt> is
ineffective, because in bottom-up mode the directories in <em>dirnames</em> are
generated before <em>dirpath</em> itself is generated.</p>
<p>By default, errors from the <a class="reference internal" href="#os.listdir" title="os.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a> call are ignored.  If optional
argument <em>onerror</em> is specified, it should be a function; it will be called with
one argument, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> instance.  It can report the error to continue
with the walk, or raise the exception to abort the walk.  Note that the filename
is available as the <tt class="docutils literal"><span class="pre">filename</span></tt> attribute of the exception object.</p>
<p>By default, <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will not walk down into symbolic links that resolve to
directories. Set <em>followlinks</em> to <tt class="docutils literal"><span class="pre">True</span></tt> to visit directories pointed to by
symlinks, on systems that support them.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Be aware that setting <em>followlinks</em> to <tt class="docutils literal"><span class="pre">True</span></tt> can lead to infinite
recursion if a link points to a parent directory of itself. <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a>
does not keep track of the directories it visited already.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you pass a relative pathname, don&#8217;t change the current working directory
between resumptions of <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a>.  <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> never changes the current
directory, and assumes that its caller doesn&#8217;t either.</p>
</div>
<p>This example displays the number of bytes taken by non-directory files in each
directory under the starting directory, except that it doesn&#8217;t look under any
CVS subdirectory:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="k">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s">&#39;python/Lib/email&#39;</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s">&quot;consumes&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s">&quot; &quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">),</span> <span class="n">end</span><span class="o">=</span><span class="s">&quot; &quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&quot;bytes in&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s">&quot;non-directory files&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="s">&#39;CVS&#39;</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;CVS&#39;</span><span class="p">)</span>  <span class="c"># don&#39;t visit CVS directories</span>
</pre></div>
</div>
<p>In the next example (simple implementation of <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><tt class="xref py py-func docutils literal"><span class="pre">shutil.rmtree()</span></tt></a>),
walking the tree bottom-up is essential, <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> doesn&#8217;t allow
deleting a directory before the directory is empty:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="c"># Delete everything reachable from the directory named in &quot;top&quot;,</span>
<span class="c"># assuming there are no symbolic links.</span>
<span class="c"># CAUTION:  This is dangerous!  For example, if top == &#39;/&#39;, it</span>
<span class="c"># could delete all your disk files.</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="k">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="os.fwalk">
<tt class="descclassname">os.</tt><tt class="descname">fwalk</tt><big>(</big><em>top='.'</em>, <em>topdown=True</em>, <em>onerror=None</em>, <em>*</em>, <em>follow_symlinks=False</em>, <em>dir_fd=None</em><big>)</big><a class="headerlink" href="#os.fwalk" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-20">This behaves exactly like <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a>, except that it yields a 4-tuple
<tt class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span> <span class="pre">filenames,</span> <span class="pre">dirfd)</span></tt>, and it supports <tt class="docutils literal"><span class="pre">dir_fd</span></tt>.</p>
<p><em>dirpath</em>, <em>dirnames</em> and <em>filenames</em> are identical to <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> output,
and <em>dirfd</em> is a file descriptor referring to the directory <em>dirpath</em>.</p>
<p>This function always supports <a class="reference internal" href="#dir-fd"><em>paths relative to directory descriptors</em></a> and <a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.  Note however
that, unlike other functions, the <a class="reference internal" href="#os.fwalk" title="os.fwalk"><tt class="xref py py-func docutils literal"><span class="pre">fwalk()</span></tt></a> default value for
<em>follow_symlinks</em> is <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Since <a class="reference internal" href="#os.fwalk" title="os.fwalk"><tt class="xref py py-func docutils literal"><span class="pre">fwalk()</span></tt></a> yields file descriptors, those are only valid until
the next iteration step, so you should duplicate them (e.g. with
<a class="reference internal" href="#os.dup" title="os.dup"><tt class="xref py py-func docutils literal"><span class="pre">dup()</span></tt></a>) if you want to keep them longer.</p>
</div>
<p>This example displays the number of bytes taken by non-directory files in each
directory under the starting directory, except that it doesn&#8217;t look under any
CVS subdirectory:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">rootfd</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">fwalk</span><span class="p">(</span><span class="s">&#39;python/Lib/email&#39;</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s">&quot;consumes&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">]),</span>
          <span class="n">end</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&quot;bytes in&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s">&quot;non-directory files&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="s">&#39;CVS&#39;</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;CVS&#39;</span><span class="p">)</span>  <span class="c"># don&#39;t visit CVS directories</span>
</pre></div>
</div>
<p>In the next example, walking the tree bottom-up is essential:
<a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> doesn&#8217;t allow deleting a directory before the directory is
empty:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="c"># Delete everything reachable from the directory named in &quot;top&quot;,</span>
<span class="c"># assuming there are no symbolic links.</span>
<span class="c"># CAUTION:  This is dangerous!  For example, if top == &#39;/&#39;, it</span>
<span class="c"># could delete all your disk files.</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">rootfd</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">fwalk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="k">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span>
</pre></div>
</div>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<div class="section" id="linux-extended-attributes">
<h3>16.1.5.1. Linux extended attributes<a class="headerlink" href="#linux-extended-attributes" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
<p>These functions are all available on Linux only.</p>
<dl class="function">
<dt id="os.getxattr">
<tt class="descclassname">os.</tt><tt class="descname">getxattr</tt><big>(</big><em>path</em>, <em>attribute</em>, <em>*</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.getxattr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value of the extended filesystem attribute <em>attribute</em> for
<em>path</em>. <em>attribute</em> can be bytes or str. If it is str, it is encoded
with the filesystem encoding.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a> and
<a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.listxattr">
<tt class="descclassname">os.</tt><tt class="descname">listxattr</tt><big>(</big><em>path=None</em>, <em>*</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.listxattr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of the extended filesystem attributes on <em>path</em>.  The
attributes in the list are represented as strings decoded with the filesystem
encoding.  If <em>path</em> is <tt class="docutils literal"><span class="pre">None</span></tt>, <a class="reference internal" href="#os.listxattr" title="os.listxattr"><tt class="xref py py-func docutils literal"><span class="pre">listxattr()</span></tt></a> will examine the current
directory.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a> and
<a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.removexattr">
<tt class="descclassname">os.</tt><tt class="descname">removexattr</tt><big>(</big><em>path</em>, <em>attribute</em>, <em>*</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.removexattr" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the extended filesystem attribute <em>attribute</em> from <em>path</em>.
<em>attribute</em> should be bytes or str. If it is a string, it is encoded
with the filesystem encoding.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a> and
<a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.setxattr">
<tt class="descclassname">os.</tt><tt class="descname">setxattr</tt><big>(</big><em>path</em>, <em>attribute</em>, <em>value</em>, <em>flags=0</em>, <em>*</em>, <em>follow_symlinks=True</em><big>)</big><a class="headerlink" href="#os.setxattr" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the extended filesystem attribute <em>attribute</em> on <em>path</em> to <em>value</em>.
<em>attribute</em> must be a bytes or str with no embedded NULs. If it is a str,
it is encoded with the filesystem encoding.  <em>flags</em> may be
<a class="reference internal" href="#os.XATTR_REPLACE" title="os.XATTR_REPLACE"><tt class="xref py py-data docutils literal"><span class="pre">XATTR_REPLACE</span></tt></a> or <a class="reference internal" href="#os.XATTR_CREATE" title="os.XATTR_CREATE"><tt class="xref py py-data docutils literal"><span class="pre">XATTR_CREATE</span></tt></a>. If <a class="reference internal" href="#os.XATTR_REPLACE" title="os.XATTR_REPLACE"><tt class="xref py py-data docutils literal"><span class="pre">XATTR_REPLACE</span></tt></a> is
given and the attribute does not exist, <tt class="docutils literal"><span class="pre">EEXISTS</span></tt> will be raised.
If <a class="reference internal" href="#os.XATTR_CREATE" title="os.XATTR_CREATE"><tt class="xref py py-data docutils literal"><span class="pre">XATTR_CREATE</span></tt></a> is given and the attribute already exists, the
attribute will not be created and <tt class="docutils literal"><span class="pre">ENODATA</span></tt> will be raised.</p>
<p>This function can support <a class="reference internal" href="#path-fd"><em>specifying a file descriptor</em></a> and
<a class="reference internal" href="#follow-symlinks"><em>not following symlinks</em></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">A bug in Linux kernel versions less than 2.6.39 caused the flags argument
to be ignored on some filesystems.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.XATTR_SIZE_MAX">
<tt class="descclassname">os.</tt><tt class="descname">XATTR_SIZE_MAX</tt><a class="headerlink" href="#os.XATTR_SIZE_MAX" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum size the value of an extended attribute can be. Currently, this
is 64 KiB on Linux.</p>
</dd></dl>

<dl class="data">
<dt id="os.XATTR_CREATE">
<tt class="descclassname">os.</tt><tt class="descname">XATTR_CREATE</tt><a class="headerlink" href="#os.XATTR_CREATE" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a possible value for the flags argument in <a class="reference internal" href="#os.setxattr" title="os.setxattr"><tt class="xref py py-func docutils literal"><span class="pre">setxattr()</span></tt></a>. It
indicates the operation must create an attribute.</p>
</dd></dl>

<dl class="data">
<dt id="os.XATTR_REPLACE">
<tt class="descclassname">os.</tt><tt class="descname">XATTR_REPLACE</tt><a class="headerlink" href="#os.XATTR_REPLACE" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a possible value for the flags argument in <a class="reference internal" href="#os.setxattr" title="os.setxattr"><tt class="xref py py-func docutils literal"><span class="pre">setxattr()</span></tt></a>. It
indicates the operation must replace an existing attribute.</p>
</dd></dl>

</div>
</div>
<div class="section" id="process-management">
<span id="os-process"></span><h2>16.1.6. Process Management<a class="headerlink" href="#process-management" title="Permalink to this headline">¶</a></h2>
<p>These functions may be used to create and manage processes.</p>
<p>The various <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">exec*</span></tt></a> functions take a list of arguments for the new
program loaded into the process.  In each case, the first of these arguments is
passed to the new program as its own name rather than as an argument a user may
have typed on a command line.  For the C programmer, this is the <tt class="docutils literal"><span class="pre">argv[0]</span></tt>
passed to a program&#8217;s <tt class="xref c c-func docutils literal"><span class="pre">main()</span></tt>.  For example, <tt class="docutils literal"><span class="pre">os.execv('/bin/echo',</span>
<span class="pre">['foo',</span> <span class="pre">'bar'])</span></tt> will only print <tt class="docutils literal"><span class="pre">bar</span></tt> on standard output; <tt class="docutils literal"><span class="pre">foo</span></tt> will seem
to be ignored.</p>
<dl class="function">
<dt id="os.abort">
<tt class="descclassname">os.</tt><tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#os.abort" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> signal to the current process.  On Unix, the default
behavior is to produce a core dump; on Windows, the process immediately returns
an exit code of <tt class="docutils literal"><span class="pre">3</span></tt>.  Be aware that calling this function will not call the
Python signal handler registered for <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> with
<a class="reference internal" href="signal.html#signal.signal" title="signal.signal"><tt class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.execl">
<tt class="descclassname">os.</tt><tt class="descname">execl</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execl" title="Permalink to this definition">¶</a></dt>
<dt id="os.execle">
<tt class="descclassname">os.</tt><tt class="descname">execle</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execle" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlp">
<tt class="descclassname">os.</tt><tt class="descname">execlp</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlpe">
<tt class="descclassname">os.</tt><tt class="descname">execlpe</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.execv">
<tt class="descclassname">os.</tt><tt class="descname">execv</tt><big>(</big><em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execv" title="Permalink to this definition">¶</a></dt>
<dt id="os.execve">
<tt class="descclassname">os.</tt><tt class="descname">execve</tt><big>(</big><em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execve" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvp">
<tt class="descclassname">os.</tt><tt class="descname">execvp</tt><big>(</big><em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvpe">
<tt class="descclassname">os.</tt><tt class="descname">execvpe</tt><big>(</big><em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>These functions all execute a new program, replacing the current process; they
do not return.  On Unix, the new executable is loaded into the current process,
and will have the same process id as the caller.  Errors will be reported as
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exceptions.</p>
<p>The current process is replaced immediately. Open file objects and
descriptors are not flushed, so if there may be data buffered
on these open files, you should flush them using
<tt class="xref py py-func docutils literal"><span class="pre">sys.stdout.flush()</span></tt> or <a class="reference internal" href="#os.fsync" title="os.fsync"><tt class="xref py py-func docutils literal"><span class="pre">os.fsync()</span></tt></a> before calling an
<a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">exec*</span></tt></a> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">exec*</span></tt></a> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the <tt class="xref py py-func docutils literal"><span class="pre">execl*()</span></tt>
functions.  The &#8220;v&#8221; variants are good when the number of parameters is
variable, with the arguments being passed in a list or tuple as the <em>args</em>
parameter.  In either case, the arguments to the child process should start with
the name of the command being run, but this is not enforced.</p>
<p>The variants which include a &#8220;p&#8221; near the end (<a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>,
<a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a>) will use the
<span class="target" id="index-21"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">exec*e</span></tt></a> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-22"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable. The other variants, <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>, <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>,
<a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, will not use the <span class="target" id="index-23"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to
locate the executable; <em>path</em> must contain an appropriate absolute or relative
path.</p>
<p>For <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a> (note
that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping which is
used to define the environment variables for the new process (these are used
instead of the current process&#8217; environment); the functions <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>,
<a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>, <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a> all cause the new process to
inherit the environment of the current process.</p>
<p>For <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a> on some platforms, <em>path</em> may also be specified as an open
file descriptor.  This functionality may not be supported on your platform;
you can check whether or not it is available using <a class="reference internal" href="#os.supports_fd" title="os.supports_fd"><tt class="xref py py-data docutils literal"><span class="pre">os.supports_fd</span></tt></a>.
If it is unavailable, using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3: </span>Added support for specifying an open file descriptor for <em>path</em>
for <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os._exit">
<tt class="descclassname">os.</tt><tt class="descname">_exit</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os._exit" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit the process with status <em>n</em>, without calling cleanup handlers, flushing
stdio buffers, etc.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The standard way to exit is <tt class="docutils literal"><span class="pre">sys.exit(n)</span></tt>.  <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a> should
normally only be used in the child process after a <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a>.</p>
</div>
</dd></dl>

<p>The following exit codes are defined and can be used with <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a>,
although they are not required.  These are typically used for system programs
written in Python, such as a mail server&#8217;s external command delivery program.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some of these may not be available on all Unix platforms, since there is some
variation.  These constants are defined where they are defined by the underlying
platform.</p>
</div>
<dl class="data">
<dt id="os.EX_OK">
<tt class="descclassname">os.</tt><tt class="descname">EX_OK</tt><a class="headerlink" href="#os.EX_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means no error occurred.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_USAGE">
<tt class="descclassname">os.</tt><tt class="descname">EX_USAGE</tt><a class="headerlink" href="#os.EX_USAGE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the command was used incorrectly, such as when the wrong
number of arguments are given.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_DATAERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_DATAERR</tt><a class="headerlink" href="#os.EX_DATAERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the input data was incorrect.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOINPUT">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOINPUT</tt><a class="headerlink" href="#os.EX_NOINPUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an input file did not exist or was not readable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOUSER">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOUSER</tt><a class="headerlink" href="#os.EX_NOUSER" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified user did not exist.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOHOST">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOHOST</tt><a class="headerlink" href="#os.EX_NOHOST" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified host did not exist.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_UNAVAILABLE">
<tt class="descclassname">os.</tt><tt class="descname">EX_UNAVAILABLE</tt><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a required service is unavailable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_SOFTWARE">
<tt class="descclassname">os.</tt><tt class="descname">EX_SOFTWARE</tt><a class="headerlink" href="#os.EX_SOFTWARE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an internal software error was detected.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSERR</tt><a class="headerlink" href="#os.EX_OSERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an operating system error was detected, such as the
inability to fork or create a pipe.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSFILE">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSFILE</tt><a class="headerlink" href="#os.EX_OSFILE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means some system file did not exist, could not be opened, or had
some other kind of error.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CANTCREAT">
<tt class="descclassname">os.</tt><tt class="descname">EX_CANTCREAT</tt><a class="headerlink" href="#os.EX_CANTCREAT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a user specified output file could not be created.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_IOERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_IOERR</tt><a class="headerlink" href="#os.EX_IOERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that an error occurred while doing I/O on some file.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_TEMPFAIL">
<tt class="descclassname">os.</tt><tt class="descname">EX_TEMPFAIL</tt><a class="headerlink" href="#os.EX_TEMPFAIL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a temporary failure occurred.  This indicates something
that may not really be an error, such as a network connection that couldn&#8217;t be
made during a retryable operation.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_PROTOCOL">
<tt class="descclassname">os.</tt><tt class="descname">EX_PROTOCOL</tt><a class="headerlink" href="#os.EX_PROTOCOL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not
understood.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOPERM">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOPERM</tt><a class="headerlink" href="#os.EX_NOPERM" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that there were insufficient permissions to perform the
operation (but not intended for file system problems).</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CONFIG">
<tt class="descclassname">os.</tt><tt class="descname">EX_CONFIG</tt><a class="headerlink" href="#os.EX_CONFIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that some kind of configuration error occurred.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOTFOUND">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOTFOUND</tt><a class="headerlink" href="#os.EX_NOTFOUND" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means something like &#8220;an entry was not found&#8221;.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fork">
<tt class="descclassname">os.</tt><tt class="descname">fork</tt><big>(</big><big>)</big><a class="headerlink" href="#os.fork" title="Permalink to this definition">¶</a></dt>
<dd><p>Fork a child process.  Return <tt class="docutils literal"><span class="pre">0</span></tt> in the child and the child&#8217;s process id in the
parent.  If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>Note that some platforms including FreeBSD &lt;= 6.3 and Cygwin have
known issues when using fork() from a thread.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">See <a class="reference internal" href="ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><tt class="xref py py-mod docutils literal"><span class="pre">ssl</span></tt></a> for applications that use the SSL module with fork().</p>
</div>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.forkpty">
<tt class="descclassname">os.</tt><tt class="descname">forkpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.forkpty" title="Permalink to this definition">¶</a></dt>
<dd><p>Fork a child process, using a new pseudo-terminal as the child&#8217;s controlling
terminal. Return a pair of <tt class="docutils literal"><span class="pre">(pid,</span> <span class="pre">fd)</span></tt>, where <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt> in the child, the
new child&#8217;s process id in the parent, and <em>fd</em> is the file descriptor of the
master end of the pseudo-terminal.  For a more portable approach, use the
<a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module.  If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>Availability: some flavors of Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.kill">
<tt class="descclassname">os.</tt><tt class="descname">kill</tt><big>(</big><em>pid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.kill" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-24">Send signal <em>sig</em> to the process <em>pid</em>.  Constants for the specific signals
available on the host platform are defined in the <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><tt class="xref py py-mod docutils literal"><span class="pre">signal</span></tt></a> module.</p>
<p>Windows: The <a class="reference internal" href="signal.html#signal.CTRL_C_EVENT" title="signal.CTRL_C_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_C_EVENT</span></tt></a> and
<a class="reference internal" href="signal.html#signal.CTRL_BREAK_EVENT" title="signal.CTRL_BREAK_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_BREAK_EVENT</span></tt></a> signals are special signals which can
only be sent to console processes which share a common console window,
e.g., some subprocesses. Any other value for <em>sig</em> will cause the process
to be unconditionally killed by the TerminateProcess API, and the exit code
will be set to <em>sig</em>. The Windows version of <a class="reference internal" href="#os.kill" title="os.kill"><tt class="xref py py-func docutils literal"><span class="pre">kill()</span></tt></a> additionally takes
process handles to be killed.</p>
<p>See also <a class="reference internal" href="signal.html#signal.pthread_kill" title="signal.pthread_kill"><tt class="xref py py-func docutils literal"><span class="pre">signal.pthread_kill()</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2: </span>Windows support.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.killpg">
<tt class="descclassname">os.</tt><tt class="descname">killpg</tt><big>(</big><em>pgid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.killpg" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-25">Send the signal <em>sig</em> to the process group <em>pgid</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.nice">
<tt class="descclassname">os.</tt><tt class="descname">nice</tt><big>(</big><em>increment</em><big>)</big><a class="headerlink" href="#os.nice" title="Permalink to this definition">¶</a></dt>
<dd><p>Add <em>increment</em> to the process&#8217;s &#8220;niceness&#8221;.  Return the new niceness.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.plock">
<tt class="descclassname">os.</tt><tt class="descname">plock</tt><big>(</big><em>op</em><big>)</big><a class="headerlink" href="#os.plock" title="Permalink to this definition">¶</a></dt>
<dd><p>Lock program segments into memory.  The value of <em>op</em> (defined in
<tt class="docutils literal"><span class="pre">&lt;sys/lock.h&gt;</span></tt>) determines which segments are locked.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.popen">
<tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>command</em>, <em>mode='r'</em>, <em>buffering=-1</em><big>)</big><a class="headerlink" href="#os.popen" title="Permalink to this definition">¶</a></dt>
<dd><p>Open a pipe to or from <em>command</em>.  The return value is an open file object
connected to the pipe, which can be read or written depending on whether <em>mode</em>
is <tt class="docutils literal"><span class="pre">'r'</span></tt> (default) or <tt class="docutils literal"><span class="pre">'w'</span></tt>. The <em>buffering</em> argument has the same meaning as
the corresponding argument to the built-in <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function. The
returned file object reads or writes text strings rather than bytes.</p>
<p>The <tt class="docutils literal"><span class="pre">close</span></tt> method returns <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if the subprocess exited
successfully, or the subprocess&#8217;s return code if there was an
error. On POSIX systems, if the return code is positive it
represents the return value of the process left-shifted by one
byte.  If the return code is negative, the process was terminated
by the signal given by the negated value of the return code.  (For
example, the return value might be <tt class="docutils literal"><span class="pre">-</span> <span class="pre">signal.SIGKILL</span></tt> if the
subprocess was killed.)  On Windows systems, the return value
contains the signed integer return code from the child process.</p>
<p>This is implemented using <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><tt class="xref py py-class docutils literal"><span class="pre">subprocess.Popen</span></tt></a>; see that class&#8217;s
documentation for more powerful ways to manage and communicate with
subprocesses.</p>
</dd></dl>

<dl class="function">
<dt id="os.spawnl">
<tt class="descclassname">os.</tt><tt class="descname">spawnl</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnl" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnle">
<tt class="descclassname">os.</tt><tt class="descname">spawnle</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnle" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlp">
<tt class="descclassname">os.</tt><tt class="descname">spawnlp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnlpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnv">
<tt class="descclassname">os.</tt><tt class="descname">spawnv</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnv" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnve">
<tt class="descclassname">os.</tt><tt class="descname">spawnve</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnve" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvp">
<tt class="descclassname">os.</tt><tt class="descname">spawnvp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnvpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the program <em>path</em> in a new process.</p>
<p>(Note that the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for
spawning new processes and retrieving their results; using that module is
preferable to using these functions.  Check especially the
<a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.)</p>
<p>If <em>mode</em> is <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, this function returns the process id of the new
process; if <em>mode</em> is <a class="reference internal" href="#os.P_WAIT" title="os.P_WAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_WAIT</span></tt></a>, returns the process&#8217;s exit code if it
exits normally, or <tt class="docutils literal"><span class="pre">-signal</span></tt>, where <em>signal</em> is the signal that killed the
process.  On Windows, the process id will actually be the process handle, so can
be used with the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the
<tt class="xref py py-func docutils literal"><span class="pre">spawnl*()</span></tt> functions.  The &#8220;v&#8221; variants are good when the number of
parameters is variable, with the arguments being passed in a list or tuple as
the <em>args</em> parameter.  In either case, the arguments to the child process must
start with the name of the command being run.</p>
<p>The variants which include a second &#8220;p&#8221; near the end (<a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>,
<a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a>) will use the
<span class="target" id="index-26"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*e</span></tt></a> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-27"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable.  The other variants, <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>,
<a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, will not use the
<span class="target" id="index-28"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to locate the executable; <em>path</em> must contain an
appropriate absolute or relative path.</p>
<p>For <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a>
(note that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping
which is used to define the environment variables for the new process (they are
used instead of the current process&#8217; environment); the functions
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>, <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a> all cause
the new process to inherit the environment of the current process.  Note that
keys and values in the <em>env</em> dictionary must be strings; invalid keys or
values will cause the function to fail, with a return value of <tt class="docutils literal"><span class="pre">127</span></tt>.</p>
<p>As an example, the following calls to <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are
equivalent:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="n">os</span><span class="o">.</span><span class="n">spawnlp</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">)</span>

<span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">]</span>
<span class="n">os</span><span class="o">.</span><span class="n">spawnvpe</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.  <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a>
and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are not available on Windows.  <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a> and
<a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a> are not thread-safe on Windows; we advise you to use the
<a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module instead.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_NOWAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAIT</tt><a class="headerlink" href="#os.P_NOWAIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_NOWAITO">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAITO</tt><a class="headerlink" href="#os.P_NOWAITO" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> family of
functions.  If either of these values is given, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions
will return as soon as the new process has been created, with the process id as
the return value.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_WAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_WAIT</tt><a class="headerlink" href="#os.P_WAIT" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible value for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> family of
functions.  If this is given as <em>mode</em>, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions will not
return until the new process has run to completion and will return the exit code
of the process the run is successful, or <tt class="docutils literal"><span class="pre">-signal</span></tt> if a signal kills the
process.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_DETACH">
<tt class="descclassname">os.</tt><tt class="descname">P_DETACH</tt><a class="headerlink" href="#os.P_DETACH" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_OVERLAY">
<tt class="descclassname">os.</tt><tt class="descname">P_OVERLAY</tt><a class="headerlink" href="#os.P_OVERLAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> family of
functions.  These are less portable than those listed above. <a class="reference internal" href="#os.P_DETACH" title="os.P_DETACH"><tt class="xref py py-const docutils literal"><span class="pre">P_DETACH</span></tt></a>
is similar to <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, but the new process is detached from the
console of the calling process. If <a class="reference internal" href="#os.P_OVERLAY" title="os.P_OVERLAY"><tt class="xref py py-const docutils literal"><span class="pre">P_OVERLAY</span></tt></a> is used, the current
process will be replaced; the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a> function will not return.</p>
<p>Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.startfile">
<tt class="descclassname">os.</tt><tt class="descname">startfile</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>operation</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.startfile" title="Permalink to this definition">¶</a></dt>
<dd><p>Start a file with its associated application.</p>
<p>When <em>operation</em> is not specified or <tt class="docutils literal"><span class="pre">'open'</span></tt>, this acts like double-clicking
the file in Windows Explorer, or giving the file name as an argument to the
<strong class="program">start</strong> command from the interactive command shell: the file is opened
with whatever application (if any) its extension is associated.</p>
<p>When another <em>operation</em> is given, it must be a &#8220;command verb&#8221; that specifies
what should be done with the file. Common verbs documented by Microsoft are
<tt class="docutils literal"><span class="pre">'print'</span></tt> and  <tt class="docutils literal"><span class="pre">'edit'</span></tt> (to be used on files) as well as <tt class="docutils literal"><span class="pre">'explore'</span></tt> and
<tt class="docutils literal"><span class="pre">'find'</span></tt> (to be used on directories).</p>
<p><a class="reference internal" href="#os.startfile" title="os.startfile"><tt class="xref py py-func docutils literal"><span class="pre">startfile()</span></tt></a> returns as soon as the associated application is launched.
There is no option to wait for the application to close, and no way to retrieve
the application&#8217;s exit status.  The <em>path</em> parameter is relative to the current
directory.  If you want to use an absolute path, make sure the first character
is not a slash (<tt class="docutils literal"><span class="pre">'/'</span></tt>); the underlying Win32 <tt class="xref c c-func docutils literal"><span class="pre">ShellExecute()</span></tt> function
doesn&#8217;t work if it is.  Use the <a class="reference internal" href="os.path.html#os.path.normpath" title="os.path.normpath"><tt class="xref py py-func docutils literal"><span class="pre">os.path.normpath()</span></tt></a> function to ensure that
the path is properly encoded for Win32.</p>
<p>Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.system">
<tt class="descclassname">os.</tt><tt class="descname">system</tt><big>(</big><em>command</em><big>)</big><a class="headerlink" href="#os.system" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the command (a string) in a subshell.  This is implemented by calling
the Standard C function <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt>, and has the same limitations.
Changes to <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, etc. are not reflected in the environment of
the executed command. If <em>command</em> generates any output, it will be sent to
the interpreter standard output stream.</p>
<p>On Unix, the return value is the exit status of the process encoded in the
format specified for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>.  Note that POSIX does not specify the
meaning of the return value of the C <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt> function, so the return
value of the Python function is system-dependent.</p>
<p>On Windows, the return value is that returned by the system shell after
running <em>command</em>.  The shell is given by the Windows environment variable
<span class="target" id="index-29"></span><tt class="xref std std-envvar docutils literal"><span class="pre">COMSPEC</span></tt>: it is usually <strong class="program">cmd.exe</strong>, which returns the exit
status of the command run; on systems using a non-native shell, consult your
shell documentation.</p>
<p>The <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for spawning
new processes and retrieving their results; using that module is preferable
to using this function.  See the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section in
the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> documentation for some helpful recipes.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.times">
<tt class="descclassname">os.</tt><tt class="descname">times</tt><big>(</big><big>)</big><a class="headerlink" href="#os.times" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the current global process times.
The return value is an object with five attributes:</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">user</span></tt> - user time</li>
<li><a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-attr docutils literal"><span class="pre">system</span></tt></a> - system time</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">children_user</span></tt> - user time of all child processes</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">children_system</span></tt> - system time of all child processes</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">elapsed</span></tt> - elapsed real time since a fixed point in the past</li>
</ul>
<p>For backwards compatibility, this object also behaves like a five-tuple
containing <tt class="xref py py-attr docutils literal"><span class="pre">user</span></tt>, <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-attr docutils literal"><span class="pre">system</span></tt></a>, <tt class="xref py py-attr docutils literal"><span class="pre">children_user</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">children_system</span></tt>, and <tt class="xref py py-attr docutils literal"><span class="pre">elapsed</span></tt> in that order.</p>
<p>See the Unix manual page
<em class="manpage">times(2)</em> or the corresponding Windows Platform API documentation.
On Windows, only <tt class="xref py py-attr docutils literal"><span class="pre">user</span></tt> and <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-attr docutils literal"><span class="pre">system</span></tt></a> are known; the other
attributes are zero.</p>
<p>Availability: Unix, Windows.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Return type changed from a tuple to a tuple-like object
with named attributes.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.wait">
<tt class="descclassname">os.</tt><tt class="descname">wait</tt><big>(</big><big>)</big><a class="headerlink" href="#os.wait" title="Permalink to this definition">¶</a></dt>
<dd><p>Wait for completion of a child process, and return a tuple containing its pid
and exit status indication: a 16-bit number, whose low byte is the signal number
that killed the process, and whose high byte is the exit status (if the signal
number is zero); the high bit of the low byte is set if a core file was
produced.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.waitid">
<tt class="descclassname">os.</tt><tt class="descname">waitid</tt><big>(</big><em>idtype</em>, <em>id</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.waitid" title="Permalink to this definition">¶</a></dt>
<dd><p>Wait for the completion of one or more child processes.
<em>idtype</em> can be <a class="reference internal" href="#os.P_PID" title="os.P_PID"><tt class="xref py py-data docutils literal"><span class="pre">P_PID</span></tt></a>, <a class="reference internal" href="#os.P_PGID" title="os.P_PGID"><tt class="xref py py-data docutils literal"><span class="pre">P_PGID</span></tt></a> or <a class="reference internal" href="#os.P_ALL" title="os.P_ALL"><tt class="xref py py-data docutils literal"><span class="pre">P_ALL</span></tt></a>.
<em>id</em> specifies the pid to wait on.
<em>options</em> is constructed from the ORing of one or more of <a class="reference internal" href="#os.WEXITED" title="os.WEXITED"><tt class="xref py py-data docutils literal"><span class="pre">WEXITED</span></tt></a>,
<a class="reference internal" href="#os.WSTOPPED" title="os.WSTOPPED"><tt class="xref py py-data docutils literal"><span class="pre">WSTOPPED</span></tt></a> or <a class="reference internal" href="#os.WCONTINUED" title="os.WCONTINUED"><tt class="xref py py-data docutils literal"><span class="pre">WCONTINUED</span></tt></a> and additionally may be ORed with
<a class="reference internal" href="#os.WNOHANG" title="os.WNOHANG"><tt class="xref py py-data docutils literal"><span class="pre">WNOHANG</span></tt></a> or <a class="reference internal" href="#os.WNOWAIT" title="os.WNOWAIT"><tt class="xref py py-data docutils literal"><span class="pre">WNOWAIT</span></tt></a>. The return value is an object
representing the data contained in the <tt class="xref c c-type docutils literal"><span class="pre">siginfo_t</span></tt> structure, namely:
<tt class="xref py py-attr docutils literal"><span class="pre">si_pid</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">si_uid</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">si_signo</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">si_status</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">si_code</span></tt> or <tt class="docutils literal"><span class="pre">None</span></tt> if <a class="reference internal" href="#os.WNOHANG" title="os.WNOHANG"><tt class="xref py py-data docutils literal"><span class="pre">WNOHANG</span></tt></a> is specified and there are no
children in a waitable state.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.P_PID">
<tt class="descclassname">os.</tt><tt class="descname">P_PID</tt><a class="headerlink" href="#os.P_PID" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_PGID">
<tt class="descclassname">os.</tt><tt class="descname">P_PGID</tt><a class="headerlink" href="#os.P_PGID" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_ALL">
<tt class="descclassname">os.</tt><tt class="descname">P_ALL</tt><a class="headerlink" href="#os.P_ALL" title="Permalink to this definition">¶</a></dt>
<dd><p>These are the possible values for <em>idtype</em> in <a class="reference internal" href="#os.waitid" title="os.waitid"><tt class="xref py py-func docutils literal"><span class="pre">waitid()</span></tt></a>. They affect
how <em>id</em> is interpreted.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.WEXITED">
<tt class="descclassname">os.</tt><tt class="descname">WEXITED</tt><a class="headerlink" href="#os.WEXITED" title="Permalink to this definition">¶</a></dt>
<dt id="os.WSTOPPED">
<tt class="descclassname">os.</tt><tt class="descname">WSTOPPED</tt><a class="headerlink" href="#os.WSTOPPED" title="Permalink to this definition">¶</a></dt>
<dt id="os.WNOWAIT">
<tt class="descclassname">os.</tt><tt class="descname">WNOWAIT</tt><a class="headerlink" href="#os.WNOWAIT" title="Permalink to this definition">¶</a></dt>
<dd><p>Flags that can be used in <em>options</em> in <a class="reference internal" href="#os.waitid" title="os.waitid"><tt class="xref py py-func docutils literal"><span class="pre">waitid()</span></tt></a> that specify what
child signal to wait for.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.CLD_EXITED">
<tt class="descclassname">os.</tt><tt class="descname">CLD_EXITED</tt><a class="headerlink" href="#os.CLD_EXITED" title="Permalink to this definition">¶</a></dt>
<dt id="os.CLD_DUMPED">
<tt class="descclassname">os.</tt><tt class="descname">CLD_DUMPED</tt><a class="headerlink" href="#os.CLD_DUMPED" title="Permalink to this definition">¶</a></dt>
<dt id="os.CLD_TRAPPED">
<tt class="descclassname">os.</tt><tt class="descname">CLD_TRAPPED</tt><a class="headerlink" href="#os.CLD_TRAPPED" title="Permalink to this definition">¶</a></dt>
<dt id="os.CLD_CONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">CLD_CONTINUED</tt><a class="headerlink" href="#os.CLD_CONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>These are the possible values for <tt class="xref py py-attr docutils literal"><span class="pre">si_code</span></tt> in the result returned by
<a class="reference internal" href="#os.waitid" title="os.waitid"><tt class="xref py py-func docutils literal"><span class="pre">waitid()</span></tt></a>.</p>
<p>Availability: Unix.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.waitpid">
<tt class="descclassname">os.</tt><tt class="descname">waitpid</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.waitpid" title="Permalink to this definition">¶</a></dt>
<dd><p>The details of this function differ on Unix and Windows.</p>
<p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and
return a tuple containing its process id and exit status indication (encoded as
for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>).  The semantics of the call are affected by the value of the
integer <em>options</em>, which should be <tt class="docutils literal"><span class="pre">0</span></tt> for normal operation.</p>
<p>If <em>pid</em> is greater than <tt class="docutils literal"><span class="pre">0</span></tt>, <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> requests status information for
that specific process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt>, the request is for the status of any
child in the process group of the current process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">-1</span></tt>, the
request pertains to any child of the current process.  If <em>pid</em> is less than
<tt class="docutils literal"><span class="pre">-1</span></tt>, status is requested for any process in the process group <tt class="docutils literal"><span class="pre">-pid</span></tt> (the
absolute value of <em>pid</em>).</p>
<p>An <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with the value of errno when the syscall
returns -1.</p>
<p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and
return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits
(shifting makes cross-platform use of the function easier). A <em>pid</em> less than or
equal to <tt class="docutils literal"><span class="pre">0</span></tt> has no special meaning on Windows, and raises an exception. The
value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose
id is known, not necessarily a child process. The <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*</span></tt></a>
functions called with <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a> return suitable process handles.</p>
</dd></dl>

<dl class="function">
<dt id="os.wait3">
<tt class="descclassname">os.</tt><tt class="descname">wait3</tt><big>(</big><em>options</em><big>)</big><a class="headerlink" href="#os.wait3" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except no process id argument is given and a
3-element tuple containing the child&#8217;s process id, exit status indication, and
resource usage information is returned.  Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt></a> for details on resource usage information.  The
option argument is the same as that provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> and
<a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.wait4">
<tt class="descclassname">os.</tt><tt class="descname">wait4</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.wait4" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except a 3-element tuple, containing the child&#8217;s
process id, exit status indication, and resource usage information is returned.
Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt></a> for details on
resource usage information.  The arguments to <a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a> are the same
as those provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.WNOHANG">
<tt class="descclassname">os.</tt><tt class="descname">WNOHANG</tt><a class="headerlink" href="#os.WNOHANG" title="Permalink to this definition">¶</a></dt>
<dd><p>The option for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> to return immediately if no child process status
is available immediately. The function returns <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">0)</span></tt> in this case.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.WCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WCONTINUED</tt><a class="headerlink" href="#os.WCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been continued
from a job control stop since their status was last reported.</p>
<p>Availability: some Unix systems.</p>
</dd></dl>

<dl class="data">
<dt id="os.WUNTRACED">
<tt class="descclassname">os.</tt><tt class="descname">WUNTRACED</tt><a class="headerlink" href="#os.WUNTRACED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been stopped but
their current state has not been reported since they were stopped.</p>
<p>Availability: Unix.</p>
</dd></dl>

<p>The following functions take a process status code as returned by
<a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">system()</span></tt></a>, <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>, or <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> as a parameter.  They may be
used to determine the disposition of a process.</p>
<dl class="function">
<dt id="os.WCOREDUMP">
<tt class="descclassname">os.</tt><tt class="descname">WCOREDUMP</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WCOREDUMP" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if a core dump was generated for the process, otherwise
return <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WIFCONTINUED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process has been continued from a job control stop,
otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFSTOPPED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSTOPPED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSTOPPED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process has been stopped, otherwise return
<tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFSIGNALED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSIGNALED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSIGNALED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process exited due to a signal, otherwise return
<tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFEXITED">
<tt class="descclassname">os.</tt><tt class="descname">WIFEXITED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFEXITED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process exited using the <em class="manpage">exit(2)</em> system call,
otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WEXITSTATUS">
<tt class="descclassname">os.</tt><tt class="descname">WEXITSTATUS</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WEXITSTATUS" title="Permalink to this definition">¶</a></dt>
<dd><p>If <tt class="docutils literal"><span class="pre">WIFEXITED(status)</span></tt> is true, return the integer parameter to the
<em class="manpage">exit(2)</em> system call.  Otherwise, the return value is meaningless.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WSTOPSIG">
<tt class="descclassname">os.</tt><tt class="descname">WSTOPSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WSTOPSIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the signal which caused the process to stop.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WTERMSIG">
<tt class="descclassname">os.</tt><tt class="descname">WTERMSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WTERMSIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the signal which caused the process to exit.</p>
<p>Availability: Unix.</p>
</dd></dl>

</div>
<div class="section" id="interface-to-the-scheduler">
<h2>16.1.7. Interface to the scheduler<a class="headerlink" href="#interface-to-the-scheduler" title="Permalink to this headline">¶</a></h2>
<p>These functions control how a process is allocated CPU time by the operating
system. They are only available on some Unix platforms. For more detailed
information, consult your Unix manpages.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
<p>The following scheduling policies are exposed if they are supported by the
operating system.</p>
<dl class="data">
<dt id="os.SCHED_OTHER">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_OTHER</tt><a class="headerlink" href="#os.SCHED_OTHER" title="Permalink to this definition">¶</a></dt>
<dd><p>The default scheduling policy.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_BATCH">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_BATCH</tt><a class="headerlink" href="#os.SCHED_BATCH" title="Permalink to this definition">¶</a></dt>
<dd><p>Scheduling policy for CPU-intensive processes that tries to preserve
interactivity on the rest of the computer.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_IDLE">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_IDLE</tt><a class="headerlink" href="#os.SCHED_IDLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Scheduling policy for extremely low priority background tasks.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_SPORADIC">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_SPORADIC</tt><a class="headerlink" href="#os.SCHED_SPORADIC" title="Permalink to this definition">¶</a></dt>
<dd><p>Scheduling policy for sporadic server programs.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_FIFO">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_FIFO</tt><a class="headerlink" href="#os.SCHED_FIFO" title="Permalink to this definition">¶</a></dt>
<dd><p>A First In First Out scheduling policy.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_RR">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_RR</tt><a class="headerlink" href="#os.SCHED_RR" title="Permalink to this definition">¶</a></dt>
<dd><p>A round-robin scheduling policy.</p>
</dd></dl>

<dl class="data">
<dt id="os.SCHED_RESET_ON_FORK">
<tt class="descclassname">os.</tt><tt class="descname">SCHED_RESET_ON_FORK</tt><a class="headerlink" href="#os.SCHED_RESET_ON_FORK" title="Permalink to this definition">¶</a></dt>
<dd><p>This flag can OR&#8217;ed with any other scheduling policy. When a process with
this flag set forks, its child&#8217;s scheduling policy and priority are reset to
the default.</p>
</dd></dl>

<dl class="class">
<dt id="os.sched_param">
<em class="property">class </em><tt class="descclassname">os.</tt><tt class="descname">sched_param</tt><big>(</big><em>sched_priority</em><big>)</big><a class="headerlink" href="#os.sched_param" title="Permalink to this definition">¶</a></dt>
<dd><p>This class represents tunable scheduling parameters used in
<a class="reference internal" href="#os.sched_setparam" title="os.sched_setparam"><tt class="xref py py-func docutils literal"><span class="pre">sched_setparam()</span></tt></a>, <a class="reference internal" href="#os.sched_setscheduler" title="os.sched_setscheduler"><tt class="xref py py-func docutils literal"><span class="pre">sched_setscheduler()</span></tt></a>, and
<a class="reference internal" href="#os.sched_getparam" title="os.sched_getparam"><tt class="xref py py-func docutils literal"><span class="pre">sched_getparam()</span></tt></a>. It is immutable.</p>
<p>At the moment, there is only one possible parameter:</p>
<dl class="attribute">
<dt id="os.sched_param.sched_priority">
<tt class="descname">sched_priority</tt><a class="headerlink" href="#os.sched_param.sched_priority" title="Permalink to this definition">¶</a></dt>
<dd><p>The scheduling priority for a scheduling policy.</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="os.sched_get_priority_min">
<tt class="descclassname">os.</tt><tt class="descname">sched_get_priority_min</tt><big>(</big><em>policy</em><big>)</big><a class="headerlink" href="#os.sched_get_priority_min" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the minimum priority value for <em>policy</em>. <em>policy</em> is one of the
scheduling policy constants above.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_get_priority_max">
<tt class="descclassname">os.</tt><tt class="descname">sched_get_priority_max</tt><big>(</big><em>policy</em><big>)</big><a class="headerlink" href="#os.sched_get_priority_max" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the maximum priority value for <em>policy</em>. <em>policy</em> is one of the
scheduling policy constants above.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_setscheduler">
<tt class="descclassname">os.</tt><tt class="descname">sched_setscheduler</tt><big>(</big><em>pid</em>, <em>policy</em>, <em>param</em><big>)</big><a class="headerlink" href="#os.sched_setscheduler" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the scheduling policy for the process with PID <em>pid</em>. A <em>pid</em> of 0 means
the calling process. <em>policy</em> is one of the scheduling policy constants
above. <em>param</em> is a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><tt class="xref py py-class docutils literal"><span class="pre">sched_param</span></tt></a> instance.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_getscheduler">
<tt class="descclassname">os.</tt><tt class="descname">sched_getscheduler</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.sched_getscheduler" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the scheduling policy for the process with PID <em>pid</em>. A <em>pid</em> of 0
means the calling process. The result is one of the scheduling policy
constants above.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_setparam">
<tt class="descclassname">os.</tt><tt class="descname">sched_setparam</tt><big>(</big><em>pid</em>, <em>param</em><big>)</big><a class="headerlink" href="#os.sched_setparam" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a scheduling parameters for the process with PID <em>pid</em>. A <em>pid</em> of 0 means
the calling process. <em>param</em> is a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><tt class="xref py py-class docutils literal"><span class="pre">sched_param</span></tt></a> instance.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_getparam">
<tt class="descclassname">os.</tt><tt class="descname">sched_getparam</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.sched_getparam" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the scheduling parameters as a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><tt class="xref py py-class docutils literal"><span class="pre">sched_param</span></tt></a> instance for the
process with PID <em>pid</em>. A <em>pid</em> of 0 means the calling process.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_rr_get_interval">
<tt class="descclassname">os.</tt><tt class="descname">sched_rr_get_interval</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.sched_rr_get_interval" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the round-robin quantum in seconds for the process with PID <em>pid</em>. A
<em>pid</em> of 0 means the calling process.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_yield">
<tt class="descclassname">os.</tt><tt class="descname">sched_yield</tt><big>(</big><big>)</big><a class="headerlink" href="#os.sched_yield" title="Permalink to this definition">¶</a></dt>
<dd><p>Voluntarily relinquish the CPU.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_setaffinity">
<tt class="descclassname">os.</tt><tt class="descname">sched_setaffinity</tt><big>(</big><em>pid</em>, <em>mask</em><big>)</big><a class="headerlink" href="#os.sched_setaffinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Restrict the process with PID <em>pid</em> (or the current process if zero) to a
set of CPUs.  <em>mask</em> is an iterable of integers representing the set of
CPUs to which the process should be restricted.</p>
</dd></dl>

<dl class="function">
<dt id="os.sched_getaffinity">
<tt class="descclassname">os.</tt><tt class="descname">sched_getaffinity</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.sched_getaffinity" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the set of CPUs the process with PID <em>pid</em> (or the current process
if zero) is restricted to.</p>
</dd></dl>

</div>
<div class="section" id="miscellaneous-system-information">
<span id="os-path"></span><h2>16.1.8. Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.confstr">
<tt class="descclassname">os.</tt><tt class="descname">confstr</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.confstr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return string-valued system configuration values. <em>name</em> specifies the
configuration value to retrieve; it may be a string which is the name of a
defined system value; these names are specified in a number of standards (POSIX,
Unix 95, Unix 98, and others).  Some platforms define additional names as well.
The names known to the host operating system are given as the keys of the
<tt class="docutils literal"><span class="pre">confstr_names</span></tt> dictionary.  For configuration variables not included in that
mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If the configuration value specified by <em>name</em> isn&#8217;t defined, <tt class="docutils literal"><span class="pre">None</span></tt> is
returned.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">confstr_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.confstr_names">
<tt class="descclassname">os.</tt><tt class="descname">confstr_names</tt><a class="headerlink" href="#os.confstr_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.cpu_count">
<tt class="descclassname">os.</tt><tt class="descname">cpu_count</tt><big>(</big><big>)</big><a class="headerlink" href="#os.cpu_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of CPUs in the system. Returns None if undetermined.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.4.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.getloadavg">
<tt class="descclassname">os.</tt><tt class="descname">getloadavg</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getloadavg" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of processes in the system run queue averaged over the last
1, 5, and 15 minutes or raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the load average was
unobtainable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.sysconf">
<tt class="descclassname">os.</tt><tt class="descname">sysconf</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.sysconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return integer-valued system configuration values. If the configuration value
specified by <em>name</em> isn&#8217;t defined, <tt class="docutils literal"><span class="pre">-1</span></tt> is returned.  The comments regarding
the <em>name</em> parameter for <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> apply here as well; the dictionary that
provides information on the known names is given by <tt class="docutils literal"><span class="pre">sysconf_names</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.sysconf_names">
<tt class="descclassname">os.</tt><tt class="descname">sysconf_names</tt><a class="headerlink" href="#os.sysconf_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.sysconf" title="os.sysconf"><tt class="xref py py-func docutils literal"><span class="pre">sysconf()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system.</p>
<p>Availability: Unix.</p>
</dd></dl>

<p>The following data values are used to support path manipulation operations.  These
are defined for all platforms.</p>
<p>Higher-level operations on pathnames are defined in the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module.</p>
<dl class="data">
<dt id="os.curdir">
<tt class="descclassname">os.</tt><tt class="descname">curdir</tt><a class="headerlink" href="#os.curdir" title="Permalink to this definition">¶</a></dt>
<dd><p>The constant string used by the operating system to refer to the current
directory. This is <tt class="docutils literal"><span class="pre">'.'</span></tt> for Windows and POSIX. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.pardir">
<tt class="descclassname">os.</tt><tt class="descname">pardir</tt><a class="headerlink" href="#os.pardir" title="Permalink to this definition">¶</a></dt>
<dd><p>The constant string used by the operating system to refer to the parent
directory. This is <tt class="docutils literal"><span class="pre">'..'</span></tt> for Windows and POSIX. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.sep">
<tt class="descclassname">os.</tt><tt class="descname">sep</tt><a class="headerlink" href="#os.sep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character used by the operating system to separate pathname components.
This is <tt class="docutils literal"><span class="pre">'/'</span></tt> for POSIX and <tt class="docutils literal"><span class="pre">'\\'</span></tt> for Windows.  Note that knowing this
is not sufficient to be able to parse or concatenate pathnames &#8212; use
<a class="reference internal" href="os.path.html#os.path.split" title="os.path.split"><tt class="xref py py-func docutils literal"><span class="pre">os.path.split()</span></tt></a> and <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><tt class="xref py py-func docutils literal"><span class="pre">os.path.join()</span></tt></a> &#8212; but it is occasionally
useful. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.altsep">
<tt class="descclassname">os.</tt><tt class="descname">altsep</tt><a class="headerlink" href="#os.altsep" title="Permalink to this definition">¶</a></dt>
<dd><p>An alternative character used by the operating system to separate pathname
components, or <tt class="docutils literal"><span class="pre">None</span></tt> if only one separator character exists.  This is set to
<tt class="docutils literal"><span class="pre">'/'</span></tt> on Windows systems where <tt class="docutils literal"><span class="pre">sep</span></tt> is a backslash. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.extsep">
<tt class="descclassname">os.</tt><tt class="descname">extsep</tt><a class="headerlink" href="#os.extsep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character which separates the base filename from the extension; for example,
the <tt class="docutils literal"><span class="pre">'.'</span></tt> in <tt class="file docutils literal"><span class="pre">os.py</span></tt>. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.pathsep">
<tt class="descclassname">os.</tt><tt class="descname">pathsep</tt><a class="headerlink" href="#os.pathsep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character conventionally used by the operating system to separate search
path components (as in <span class="target" id="index-30"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt>), such as <tt class="docutils literal"><span class="pre">':'</span></tt> for POSIX or <tt class="docutils literal"><span class="pre">';'</span></tt> for
Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.defpath">
<tt class="descclassname">os.</tt><tt class="descname">defpath</tt><a class="headerlink" href="#os.defpath" title="Permalink to this definition">¶</a></dt>
<dd><p>The default search path used by <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">exec*p*</span></tt></a> and
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawn*p*</span></tt></a> if the environment doesn&#8217;t have a <tt class="docutils literal"><span class="pre">'PATH'</span></tt>
key. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.linesep">
<tt class="descclassname">os.</tt><tt class="descname">linesep</tt><a class="headerlink" href="#os.linesep" title="Permalink to this definition">¶</a></dt>
<dd><p>The string used to separate (or, rather, terminate) lines on the current
platform.  This may be a single character, such as <tt class="docutils literal"><span class="pre">'\n'</span></tt> for POSIX, or
multiple characters, for example, <tt class="docutils literal"><span class="pre">'\r\n'</span></tt> for Windows. Do not use
<em>os.linesep</em> as a line terminator when writing files opened in text mode (the
default); use a single <tt class="docutils literal"><span class="pre">'\n'</span></tt> instead, on all platforms.</p>
</dd></dl>

<dl class="data">
<dt id="os.devnull">
<tt class="descclassname">os.</tt><tt class="descname">devnull</tt><a class="headerlink" href="#os.devnull" title="Permalink to this definition">¶</a></dt>
<dd><p>The file path of the null device. For example: <tt class="docutils literal"><span class="pre">'/dev/null'</span></tt> for
POSIX, <tt class="docutils literal"><span class="pre">'nul'</span></tt> for Windows.  Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.RTLD_LAZY">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_LAZY</tt><a class="headerlink" href="#os.RTLD_LAZY" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_NOW">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_NOW</tt><a class="headerlink" href="#os.RTLD_NOW" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_GLOBAL">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_GLOBAL</tt><a class="headerlink" href="#os.RTLD_GLOBAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_LOCAL">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_LOCAL</tt><a class="headerlink" href="#os.RTLD_LOCAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_NODELETE">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_NODELETE</tt><a class="headerlink" href="#os.RTLD_NODELETE" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_NOLOAD">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_NOLOAD</tt><a class="headerlink" href="#os.RTLD_NOLOAD" title="Permalink to this definition">¶</a></dt>
<dt id="os.RTLD_DEEPBIND">
<tt class="descclassname">os.</tt><tt class="descname">RTLD_DEEPBIND</tt><a class="headerlink" href="#os.RTLD_DEEPBIND" title="Permalink to this definition">¶</a></dt>
<dd><p>Flags for use with the <a class="reference internal" href="sys.html#sys.setdlopenflags" title="sys.setdlopenflags"><tt class="xref py py-func docutils literal"><span class="pre">setdlopenflags()</span></tt></a> and
<a class="reference internal" href="sys.html#sys.getdlopenflags" title="sys.getdlopenflags"><tt class="xref py py-func docutils literal"><span class="pre">getdlopenflags()</span></tt></a> functions.  See the Unix manual page
<em class="manpage">dlopen(3)</em> for what the different flags mean.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</dd></dl>

</div>
<div class="section" id="miscellaneous-functions">
<span id="os-miscfunc"></span><h2>16.1.9. Miscellaneous Functions<a class="headerlink" href="#miscellaneous-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.urandom">
<tt class="descclassname">os.</tt><tt class="descname">urandom</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os.urandom" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string of <em>n</em> random bytes suitable for cryptographic use.</p>
<p>This function returns random bytes from an OS-specific randomness source.  The
returned data should be unpredictable enough for cryptographic applications,
though its exact quality depends on the OS implementation.  On a Unix-like
system this will query <tt class="docutils literal"><span class="pre">/dev/urandom</span></tt>, and on Windows it will use
<tt class="docutils literal"><span class="pre">CryptGenRandom()</span></tt>.  If a randomness source is not found,
<a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> will be raised.</p>
<p>For an easy-to-use interface to the random number generator
provided by your platform, please see <a class="reference internal" href="random.html#random.SystemRandom" title="random.SystemRandom"><tt class="xref py py-class docutils literal"><span class="pre">random.SystemRandom</span></tt></a>.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">16.1. <tt class="docutils literal"><span class="pre">os</span></tt> &#8212; Miscellaneous operating system interfaces</a><ul>
<li><a class="reference internal" href="#file-names-command-line-arguments-and-environment-variables">16.1.1. File Names, Command Line Arguments, and Environment Variables</a></li>
<li><a class="reference internal" href="#process-parameters">16.1.2. Process Parameters</a></li>
<li><a class="reference internal" href="#file-object-creation">16.1.3. File Object Creation</a></li>
<li><a class="reference internal" href="#file-descriptor-operations">16.1.4. File Descriptor Operations</a><ul>
<li><a class="reference internal" href="#querying-the-size-of-a-terminal">16.1.4.1. Querying the size of a terminal</a></li>
<li><a class="reference internal" href="#inheritance-of-file-descriptors">16.1.4.2. Inheritance of File Descriptors</a></li>
</ul>
</li>
<li><a class="reference internal" href="#files-and-directories">16.1.5. Files and Directories</a><ul>
<li><a class="reference internal" href="#linux-extended-attributes">16.1.5.1. Linux extended attributes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#process-management">16.1.6. Process Management</a></li>
<li><a class="reference internal" href="#interface-to-the-scheduler">16.1.7. Interface to the scheduler</a></li>
<li><a class="reference internal" href="#miscellaneous-system-information">16.1.8. Miscellaneous System Information</a></li>
<li><a class="reference internal" href="#miscellaneous-functions">16.1.9. Miscellaneous Functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="allos.html"
                        title="previous chapter">16. Generic Operating System Services</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="io.html"
                        title="next chapter">16.2. <tt class="docutils literal"><span class="pre">io</span></tt> &#8212; Core tools for working with streams</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/os.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="16.2. io — Core tools for working with streams"
             >next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="16. Generic Operating System Services"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" >16. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Apr 27, 2015.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
    </div>

  </body>
</html>